Automatically copying main and related sub records

  • Thread starter Stephen Jame Pattenden
  • Start date
S

Stephen Jame Pattenden

I am trying to create a macro/vba that will automatically copy a master
record and its related sub records into a new master record with the same
related sub records.

Automatically copying the main record is simple, but being able to copy all
the related sub records and pasting them into a new main record - to which
they would then be related is proving to be quite difficult.

Any suggestions would be greatfully received.
 
K

Ken Snell \(MVP\)

To copy the subrecords, you'll need to know the original master record's
primary key value, and the newly copied master record's primary key value.
Then you run an append query that uses the original master record's primary
key value in the WHERE clause for selecting the subrecords, and that uses
the newly copied master record's primary key value in the VALUES (or SELECT)
clause for the new subrecords' foreign key field.
 

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