上次我发的那个问题,我已解决!
'从出库表中抽出数据来填充月结表,如果月结表中有相同的,则update ,否则addnew
'('查询月结表)
Dim cc As New ADODB.Recordset
Dim vv As String
vv = "select * from 月结表"
cc.Open vv, conn, adOpenKeyset, adLockPessimistic
'打开出货表
Dim kk As String
Dim tt As New ADODB.Recordset
kk = "select 名称,规格,sum(数量) as 入库总量 from 出货表 where 货物类型 like '" & Combo2.Text & "' and 日期 like '" & a & "'+'-'+ '" + Combo1.Text + "'+ '%' group by 名称,规格"
tt.Open kk, conn, adOpenKeyset, adLockPessimistic
If tt.BOF = False Then
For i = 1 To tt.RecordCount
For j = 1 To cc.RecordCount
If cc.Fields("货物名称") = tt.Fields("名称") And cc.Fields("货物规格") = tt.Fields("规格") Then
cc.Fields(4) = tt.Fields(2)
cc.Update
Exit For
Else
cc.AddNew
cc.Fields(0) = Combo2.Text
cc.Fields(1) = tt.Fields(0)
cc.Fields(2) = tt.Fields(1)
cc.Fields(4) = tt.Fields(2)
cc.Update
End If
cc.MoveNext
Next
tt.MoveNext
Next
t.Close
cc.Close
End If
执行以上代码时老是只执行addnew,尽管库中有两个完全的数(名称,规格同)这是为什么??
(说明数据库的查询语句没有错,我运行过正错,错就错在两个FOR语句)