我的第一个倾向是使用交叉表查询。但是,这可能会有点毛茸茸。
如何在模块中剪切一些 VBA 代码以将它们连接在一起,然后插入另一个表(如下所示 - 完全未经测试并且可能在某处损坏)?
dim strAbsent as string
dim currPhone as string
dim lastPhone as string
Dim db As Database
Dim rstAbsent As Recordset
Dim rstAbsentReport As Recordset
Set db = CurrentDb
Set rstAbsent = dbV.OpenRecordset("select * from Absent", _
dbOpenDynaset, dbSeeChanges)
Set rstAbsentReport = dbV.OpenRecordset("select * from AbsentReport", _
dbOpenDynaset, dbSeeChanges)
'...
do while not rstAbsentReport.EOF
currPhone = rstAbsentReport("phone")
lastPhone = currPhone
do while currPhone = lastPhone _
and not rstAbsentReport.EOF
strAbsent = strAbsent & ";" & rstAbsentReport ("comment")
'Yes I know concatenating strings this way is terribly inefficient
rstAbsentReport.MoveNext
if not rstAbsentReport.EOF then
currPhone = rstAbsentReport("phone")
end if
last
rstAbsent.AddNew
rstAbsent ("call") = strAbsent
rstAbsent.Update
loop
'... clean up of recordset variables left as an exercise