Question Create duplicate sets of data for parent with children and childrens children (1 Viewer)

SusiV

New member
Local time
Today, 07:31
Joined
Jun 7, 2013
Messages
4
I have the following tables in my Access database.

A < B < C < D

(The "<" represents a one to many relationship.)

A given row in table A can have up to 4 children (stages) in table B (stages 1 to 4).

The other one to many relationships do not have any limitations as far as the number of children are concerned.

All tables have AutoNumber primary keys.

When the user clicks a button in a form, I want to:

Copy all data in the current stage (current row) in table B (corresponding to a given parent row in table A), to the next stage in table B.
All data in child tables must be included in the copy process.

In other words, for a given row in table A, by use of buttons in the forms for each of the stages 1 – 3, the user shall be able to do the following:
all data for stage 1 are copied to stage 2 (for user modification), then
all data for stage 2 are copied to stage 3 (for user modification), then
all data for stage 3 are copied to stage 4

Is it possible to do this in Access 2010?
If yes, how?

Queries?
Triggers?
Vba?
Macros?
 

MarlaC

Registered User.
Local time
Today, 01:31
Joined
Aug 1, 2013
Messages
82
You can do it with an append query based on copying the current record (use a reference to the field with the record identifier in the form, eg., Forms!frmName!recordID as criterion for the query) in the same table. Run via VBA with a DoCmd.OpenQuery statement.
 

SusiV

New member
Local time
Today, 07:31
Joined
Jun 7, 2013
Messages
4
Thanks Marla, but I don't quite understand what you mean.
I need data in the child tables to be copied along With the parents, are you suggesting there is a command to do that?
If yes, could you show me som example code?

Thanks in advance!
 

MarlaC

Registered User.
Local time
Today, 01:31
Joined
Aug 1, 2013
Messages
82
Susi, If you gave specific field and table names, I could give you more exactly, but here's a rough go to give you an idea. In the OnClick event for your button, you'll have code to run an append query to copy the data. The query could look like so, approximately:
Code:
INSERT INTO tblB ( tblAUniqueID, Field2, Field3, Field4 )
SELECT tblB.tblBForeignKeytotblA, tblB.Field2, tblB.Field3, tblB.Field4
FROM tblA INNER JOIN tblB ON tblA.tblAUniqueID = tblB.tblBForeignKeytotblA
WHERE (((tblB.AccommodationID)=[Forms]![frmName]![currRecID]) AND (([tblBForeignKeytotblA])=[Forms]![frmName]![lngtblAUniqueID]));

Assuming that's saved as qryapptblB, you'd need code behind the command button saying
Code:
DoCmd.OpenQuery "qryapptblB", acViewNormal, acEdit
(and preferably error handling as well). You could use one button, "Copy to Next Stage", assuming you can count on the cursor to be on the correct record to copy.

If you need more specific instructions, please either post your database (scrubbed of any proprietary/private data) or the exact table and field names involved.
 

Mihail

Registered User.
Local time
Today, 08:31
Joined
Jan 22, 2011
Messages
2,373
Answer for original question:
Yes, and there are more than one ways. But WHY ?!?!?!?
I'm absolutely sure that you have no need to do this.
And I bet all my money that you come from the Excel environment.
 

Users who are viewing this thread

Top Bottom