Copying records with DAO

J

Jean

Think I may have posted my original question inadvertantly
in the wrong area, can't see it here where it should be.

What I need to do is have the user click a button on the
form. The click event causes a copy of the current record
to be added to the current recordset. This, I can do.
However, the existing record will have child records in a
child table and I need to be able to identify the child
records and copy them. The foreign key for that links
these child records to the parent record will need to be
the primary key from the newly added parent record. I
need help to copy all child records from the original
table and make sure they have the correct value for the
foreign key.

Hope someone out there is a lot more expert with DAO than
me !

TIA

Jean
 
M

Marshall Barton

Jean said:
Think I may have posted my original question inadvertantly
in the wrong area, can't see it here where it should be.

What I need to do is have the user click a button on the
form. The click event causes a copy of the current record
to be added to the current recordset. This, I can do.
However, the existing record will have child records in a
child table and I need to be able to identify the child
records and copy them. The foreign key for that links
these child records to the parent record will need to be
the primary key from the newly added parent record. I
need help to copy all child records from the original
table and make sure they have the correct value for the
foreign key.

Just execute an Insert Into query that selects for the
original record's key.

db.Execute "INSERT INTO childtable " & _
"SELECT " & newkey & ", fielda, fieldb, . . . " & _
"FROM childtable " & _
"WHERE key = " & oldkey, dbFailOnError
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top