我需要在窗体关闭时执行一个查询(在 Sub Form_Unload
)基于t1.name=t2.name从\t1更新t2.id \。因此,它必须将行转换为列,并将结果与名称匹配。仅用一个sql查询或vba就可以做到这一点吗?
T1 T2
ID | Name ID | Name | id_from_t1
1 Bob 1 Bob 1, 2
2 Bob 2 Joe 3, 4
3 Joe 3 Mark 5
4 Joe 4 Bill 6
5 Mark
6 Bill
1条答案
按热度按时间z18hc3ub1#
我是这样解决问题的
sub遍历要更新的表(t2)
' Concatenate multiple values in a query. From:
' https://stackoverflow.com/questions/5174362/microsoft-access-condense-multiple-lines-in-a-table/5174843#5174843
'
' Note that using a StringBuilder class from here:
' https://codereview.stackexchange.com/questions/67596/a-lightning-fast-stringbuilder/154792#154792
' offers no code speed up
Public Function GetListOptimal( _
SQL As String, _
Optional fieldDelim As String = ", ", _
Optional recordDelim As String = vbCrLf _
) As String
' added MoveLast to get the real number of rows
If rs.recordCount > 0 Then
rs.MoveLast
recordCount = rs.recordCount
rs.MoveFirst
End If
End Function