adding record multiple times to a table

Robster

Registered User.
Local time
Yesterday, 22:08
Joined
Mar 13, 2014
Messages
60
I need to create a query which will append the record selected in a form into a table (Print_Table) many times depending on the number in the field Quantity. The form has a dropdown list connected to a table called products.
eg.
Table products
SKU, Description, Barcode
101, product1, 543543543
102, product2, 554544544
103, product3, 567567567
104, product4, 568568568

Form
quantity= 5, SKU= 102

so I need to enter 102, product2, 554544544 into a table called Print_table five times.
 
difficult to do as a straight query, you will need a loop in VBA - something like this in the click event of a button for example.

Code:
dim I as integer
 for I=1 to me.quantity
   currentdb.execute("INSERT INTO Print_Table (SKU, Description, BarCode) VALUES ("& me.sku & ", '" & me.description & "', " & me.barcode & ")",dbfailonerror)
next i

note that description is a reserved word, so recommend you change it to something more meaningful such as PrintDescription. If you don't, at some point you will waste hours trying to track down random errors with a misleading descriptions
 

Users who are viewing this thread

Back
Top Bottom