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

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
 
Hi!


Dim rstOPQ As Recordset
Dim rst As Recordset

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

While not rstOPQ.eof
rst.AddNew
rst![CUSTNO] = rstOPQ![CUSTNO]
rst![CARDCOMP] = rstOPQ![CARDCOMP]
rst![CARDNAME] = rstOPQ![CARDNAME]
rst![TOLLFREENO] = rstOPQ![TOLLFREENO]
rst![CARDAXNO] = rstOPQ![CARDAXNO]
rst.Update
rstOPQ.MoveNext
Wend
rst.close
rstOPQ.close
set rst=Nothing
set rstOPQ=nothing

Aivars


 
Thank you very much! The entire data set duplicates to from the OrderProduct table to the CCIN table. One problem, if the OrderProduct!Card_Qty value is "2", there should be two rows of the same record in the CCIN table. In essence, the number of rows of data in CCIN should be the same as the value in the OrderProduct!Card_Qty. Any additional suggestions?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top