Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to replicate records based on a variable

Status
Not open for further replies.

henio

MIS
Jun 25, 2003
60
GB
Hi all,
I have an Excel spreadsheet which could be loaded into a table) which looks like:

Description Qty
Beer 2
Wine 5
Spirits 8

I need to create a table which looks like:

Beer 2
Beer 2
Wine 5
Wine 5
Wine 5
Wine 5
Wine 5
Spirits 8
Spirits 8
etc.

Can anyone please help?
Cheers,
Henio
 
You can use VBA :

'first, put the first table on a recordset

dim rec as DAO.Recordset
set rec = CurrentDB.OpenRecordset("Name of the first table")

'then, for each line of the first table, insert
some lines into the second
Dim i as Integer
Dim str as String
Do While rec.EOF = False
For i=1 To rec("Qty")
str = "INSERT INTO nameOfTheSecondTable _
Select '" & rec("Description") & _
"', " & rec("Qty") & " ;"
DoCmd.RunSQL (str)
Next i
rec.MoveNext
loop

rec.close

I hope it'll work !!!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top