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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate a record from one table to another 1

Status
Not open for further replies.

djfeldspiff

Programmer
Apr 26, 2001
16
US
I have the following piece of code behind a command button within a sub. My goal is to examine a record from the OrderProduct table and, pending the value in the Card_Qty field, duplicate the record in the CCIN table based on the OrderProduct!Card_Qty value. The problems is I'm only getting the first record from the OrderProduct table to process but not all of the data. Any help/direction would be greatly appreciated.

Thanks!

DJF



Dim rstOPQ As Recordset
Dim rst As Recordset
Dim intCounter As Integer

Set rstOPQ = CurrentDb.OpenRecordset("OrderProduct")
Set rst = CurrentDb.OpenRecordset("CCIN")

For intCounter = 1 To rstOPQ!Card_Qty
rst.AddNew
rst![CUSTNO] = rstOPQ![CUSTNO]
rst![CARDCOMP] = rstOPQ![CARDCOMP]
rst![CARDNAME] = rstOPQ![CARDNAME]
rst![TOLLFREENO] = rstOPQ![TOLLFREENO]
rst![CARDAXNO] = rstOPQ![CARDAXNO]
rst.Update
Next
 
If you are wanting to step through all of the records of OrderProduct, then after you do all of your processing for an OrderProduct record, you need to do:

rstOPQ.movenext

to move to the next record in the OrderProduct table. If you want to loop through the entire OrderProduct table, you can add an another loop outside of your For loop like this...

do While not rstOPQ.eof and not rstOPQ.bof
<your for loop here>
rstOPQ.movenext
loop

this will loop through the entire OrderProduct table processing your For loop for each record. (Hopefully I didn't screw up the syntax!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top