老骆 发表于:2015-04-25 16:11:49
A表:大米来货3袋,面粉来货2袋,如何自动生成B表5个记录数据,分别对应3个大米和2个面粉如附件EXCEL 左边到右边的效果
临时订购表
Private Sub Command1_Click()
Dim i As Long, j As Long
Dim rsA As adodb.Recordset, rsB As adodb.Recordset
Set rsA = New adodb.Recordset
Set rsB = New adodb.Recordset
rsA.Open "select * from A", CurrentProject.Connection, adOpenStatic, adLockOptimistic
rsB.Open "select * from B", CurrentProject.Connection, adOpenStatic, adLockOptimistic
With rsB
For i = 0 To rsA.RecordCount - 1
For j = 0 To rsA("数量") - 1
.AddNew
rsB("名称") = rsA("名称")
rsB("数量") = 1
rsB.Update
Next
rsA.MoveNext
Next
End With
rsB.Close
Set rsB = Nothing
rsA.Close
Set rsA = Nothing
Me.Recalc