|
本帖最后由 todaynew 于 2011-6-27 17:49 编辑
文棣 发表于 2011-6-27 15:19
回复 todaynew 的帖子
对for循环使用较少
Dim i As Integer
Dim stemp As String
Dim Rs As New ADODB.Recordset
Dim Rs1 As New ADODB.Recordset
stemp = "Select * From 库存"
Rs1.Open stemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If Rs1.RecordCount = 0 Then Exit Sub
'更新库存明细表
For i = 1 To Rs1.RecordCount
stemp = "Select * From 库存明细 where 条码号='" & Rs1("条码号").Value & "' and 商品编号='" & Rs1("商品编号").Value & "'"
Rs.Open stemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If Rs.RecordCount = 0 Then
Rs.AddNew '无对应记录则追加
End If
Rs("产品名称").Value = Rs1("产品名称").Value
Rs("日期").Value = Rs1("日期").Value
Rs("型号规格").Value = Rs1("型号规格").Value
Rs("数量").Value = Nz(Rs("数量").Value, 0) + Rs1("数量").Value
Rs("单价").Value = Rs1("零售价").Value
Rs("金额").Value = Rs("数量").Value * Rs("单价").Value
Rs("仓库号").Value = Rs1("仓库号").Value
Rs("类别").Value = Rs1("类别").Value
Rs("商品编号").Value = Rs1("编号").Value
Rs("毛利率").Value = Rs1("毛利率").Value
Rs("条码号").Value = Rs1("条码号").Value
Rs.Update
Rs1.MoveNext
Rs.Close
Next
'删除库存表中记录
for i=1 to Rs1.RecordCount
rs1.delete
rs1.update
rs1.movenext
next
Me.库存_子窗体2.Requery
Rs1.Close
Set Rs = Nothing
Set Rs1 = Nothing
|
|