Hi there,
One of my user's forms needs a "copy" function where they can create a new record, choose another record to copy from then copy only certain data from that record to the new record. I have two recordsets. Should I do a loop of some sort to loop through the selected records from source and copy to the target? I don't k now how to do this...
(strCurrent is the target ID and strPlan is the Source they chose from the list. THis is all working fine)
Dim dbs As DAO.Database, rstFrom As DAO.Recordset, rstTo As DAO.Recordset
Set dbs = CurrentDb
Set rstFrom = dbs.OpenRecordset("SELECT * FROM PDTL WHERE CPLANID = '" & strPlan & "'"
Set rstTo = dbs.OpenRecordset("SELECT * FROM PDTL WHERE CPLANID = '" & strCurrent & "'"
rstTo.AddNew
rstTo!CPLANID = strCurrent
rstTo!CCATGID = rstFrom!CCATGID
rstTo!CPARTID = rstFrom!CPARTID
rstTo!NCATGQTY = rstFrom!NCATGQTY
rstTo.Update
This works great for the first record, no prob. But there can be as many as 100 that need to be copied. When I do a DO LOOP it adds an infinite number of the first record and I have to stop it CTRL-BREAK. How do I make it loop each record from the Source and add it to the targer? Thoughts would be appreciated. Thanks.
One of my user's forms needs a "copy" function where they can create a new record, choose another record to copy from then copy only certain data from that record to the new record. I have two recordsets. Should I do a loop of some sort to loop through the selected records from source and copy to the target? I don't k now how to do this...
(strCurrent is the target ID and strPlan is the Source they chose from the list. THis is all working fine)
Dim dbs As DAO.Database, rstFrom As DAO.Recordset, rstTo As DAO.Recordset
Set dbs = CurrentDb
Set rstFrom = dbs.OpenRecordset("SELECT * FROM PDTL WHERE CPLANID = '" & strPlan & "'"
Set rstTo = dbs.OpenRecordset("SELECT * FROM PDTL WHERE CPLANID = '" & strCurrent & "'"
rstTo.AddNew
rstTo!CPLANID = strCurrent
rstTo!CCATGID = rstFrom!CCATGID
rstTo!CPARTID = rstFrom!CPARTID
rstTo!NCATGQTY = rstFrom!NCATGQTY
rstTo.Update
This works great for the first record, no prob. But there can be as many as 100 that need to be copied. When I do a DO LOOP it adds an infinite number of the first record and I have to stop it CTRL-BREAK. How do I make it loop each record from the Source and add it to the targer? Thoughts would be appreciated. Thanks.