我有一个包含ID
,product number
,product description
,qty
字段的表。
现在,我想创建一个新表,其中包含由父表的qty
字段给出的大量记录。
例如,如果父表中有一个带有qty = 6
的记录,那么它应该在子表中创建6
记录,其序列号从1到6。
答案 0 :(得分:1)
您可以使用一个简单的循环,如下所示:
Dim rs As DAO.Recordset
Dim Record As Integer
Dim Records As Integer
Set rs = CurrentDb.OpenRecordset("Select * From YourTable")
' Count of records - use value from your quantity field:
Records = 5
For Record = 1 To Records
rs.AddNew
rs!SomeID.Value = Record
rs!Field1.Value = SomeValue
rs!Field2.Value = SomeOtherValue
rs!Field3.Value = YetAnotherValue
rs.Update
Next
rs.Close
Set rs = Nothing
答案 1 :(得分:1)
您可以使用下面的代码。
Dim rsTable1 as Recordset
Dim rsTable2 as Recordset
Dim Table1qty as integer
Dim i as integer
set rsTable1 = CurrentDb.openrecordset("SELECT qty FROM Table1")
set rsTable2 = CurrentDB.openRecordSet("SELECT * From Table2")
if rsTable1.RecordCount > 0 then
while not rsTable1.EOF
Table1qty = rsTable("qty")
for i = 1 to Table1qty
rsTable2.Addnew
rsTable2!SerialNumber.Value = i
rsTable2!SomeField.Value = SomeValue
rsTable2.Update
next
rsTable1.movenext
wend
end