把第二个回复附件的“表格3”的“备注1“字段更改为数值(例如小数),然后把“第二步”的事件更改为:
Private Sub Command1_Click()
Dim rstA As Recordset
Dim rstB As Recordset
Dim i, j As Long
' Dim str
Dim tl As Double
CurrentDb.Execute "delete * from 表格3"
CurrentDb.Execute "insert into 表格3(编码,备注) select 编码,备注 from 表格2 group by 编码,备注"
Set rstA = CurrentDb.OpenRecordset("select * from 表格3 ")
Set rstB = CurrentDb.OpenRecordset("表格2")
rstA.MoveLast
rstA.MoveFirst
For i = 1 To rstA.RecordCount
Set rstB = CurrentDb.OpenRecordset("select 备注1 from 表格2 where 编码='" & rstA.Fields("编码") & "' and 备注='" & rstA.Fields("备注") & "'")
' str = ""
tl = 0
rstB.MoveLast
rstB.MoveFirst
For j = 1 To rstB.RecordCount
' Debug.Print j; str; Nz(rstB.Fields(0), "")
' str = str & "," & Nz(rstB.Fields(0), "")
tl = tl + CLng(Nz(rstB.Fields(0), ""))
rstB.MoveNext
Next j
' Debug.Print i; str
rstB.Close
Set rstB = Nothing
With rstA
.Edit
.Fields("备注1") = tl
' .Fields("备注1") = Mid(str, 2)
.Update
End With
rstA.MoveNext
Next i
rstA.Close
Set rstA = Nothing
DoCmd.OpenTable "表格3"
End Sub