Using a form to update two tables

pauld118

Registered User.
Local time
Today, 09:08
Joined
Jun 17, 2011
Messages
21
Hello,

I have a form (ECDataEntry; Main Form) that will populate a Case ID table (Parent Table). CaseID table has a primary key (PK), that is the foreign key (FK) of 3 tables (Child Tables). These 3 tables also have forms that populate them. For instance, one of tables where PK acts as a FK is Inspections that is populated by the form AddInspections

I'd like to create a button on the main form. This button shall save the record when data is entered and make visible the Details of the Main form. The Detail of the Mainform have a button that opens the AddInspection Form and a label that shows the CaseID Number of the record just created.

When this button is clicked I need some code to copy the primary key in the CaseID table to the Inspections Table, to populate the FK field on the Inspection table. This mean that one Case ID may have many inspections records. The Label will also need to change each time a new record is save.

Any help or better way to do this will be appreciate it. Thanks!
 
I don't know if I understand fully but if you are just trying to make sure your other forms opens up to your new record and assign the primary key from the main form to your fk field. Then you could always do something like this.


DoCmd.OpenForm "Details", acNormal
Forms![Details].FK.Value = Me.Bookmark

And just set the properties of the Details form to be [Data Entry] = True. This way it goes to a new record everytime and passes the currently new records it to the fk field on the details form.

Haven't tested it but it might work.
 
Thanks!

Let me rephrase it :). First, the Details of a form is the section that is belos the Form Header in Design view. As Header and Footers of the Forms, the Detail o can be visible or invisible.

Having said that my question is, should I write the code on the On Click Event of the button that will open the new form?? Thank you very much
 
Use the OpenArgs argument of the OpenForm method to carry the key to the OpenArgs property of the form being opened.

Then use use either the BeforeInsert or BeforeUpdate Event of the daughter form to enter the OpenArgs property value on new records.
 
Galaxiom, would you please write de code. Idk what's the open argument??
 
Haven't got time at the moment but the topic has been covered in the forum fairly recently.

Here is OpenForm Method which will tell you about OpenArgs.

And the OpenArgs Property of the form which has an example of using it to goto a record after the form opens.
 

Users who are viewing this thread

Back
Top Bottom