Duplicate related records (Versioning) (1 Viewer)

jerem

Registered User.
Local time
Today, 20:06
Joined
May 1, 2012
Messages
118
Hi,
I am trying to create a versioning function in Ms Access. That means that I have a bunch of related data that I would like to duplicate with a new version number, also the child records should be duplicated and linked to the newly duplicated items. I can't get my head around what the best approach would be. Do I need to do that in a loop that goes through each record, duplicates it, then uses the newly created PK (e.g. ID) to create the child records with that PK as FK (e.g. OrderID) ? Or is there a way to do that in one query?
Thanks!
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 22:06
Joined
Jan 20, 2009
Messages
12,852
Good database design avoids duplicating anything because that would breach normalization.

It sounds to me like there should be a related table with multiple records for the versions related by the original PK.
 

jerem

Registered User.
Local time
Today, 20:06
Joined
May 1, 2012
Messages
118
I see what you mean but in this case it seems necessary. Here is how it looks: There is an item which is the source of the main form. Then there is a subform (continuous form) with a Master/Child link with a bunch of sub-items. Then there are two other subforms (continuous forms) with parameters with a Master/Child link to the sub-item subform. So the table structure is One Item to Many sub-items. Then each one sub-items to many parameters1 and many parameters2. The user wants to be able to save/freeze a version (version 1) of all the items with all the related sub-items and parameters, and start with a copy of all that to make changes (version 2). Then he wants to be able to switch between version 1 and 2.
So the idea is to keep the item as is but duplicate all the sub-items and parameters, and create the link (PK->FK) between the duplicated sub-items and the duplicated parameters.
I know I could create a loop that goes through each records get the PK in a variable then run an append query on the child table with the saved PK variable as a FK... But could isn't there a cleverer way to do that all in one time. or in one query?
Thank you.
 
Last edited:

Galaxiom

Super Moderator
Staff member
Local time
Today, 22:06
Joined
Jan 20, 2009
Messages
12,852
Use an append query against the child tables with a select based on the foreign key of the subform records that are being duplicated while inserting the new Version value.
 

Users who are viewing this thread

Top Bottom