Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Synchronizing data between 2 forms

Status
Not open for further replies.

Jimmy211

Technical User
Aug 8, 2002
42
US
I have two forms (Form1 & Form2) linked to two separate tables (Table1 & Table2), respectively. The tables are linked in a one-to-one relationship based on Table1's primary key. My intent is to have a record be required for Table1 and optional in Table2.

I have on Form1 a button that opens Form2, and looks up the matching data based on Table1's primary key. It works well if the data exists, but the problem I'm having is entering a new record on Form2 if data doesn't exist. I can't get the primary key from Form1 to automatically be entered into its field on Form2. I've tried passing the value of the primary key to Form2 using the OpenArgs property of the OpenForm command and then setting the default value of the tracking field on Form2 to the OpenArg value, but this doesn't seem to work. Is there an easier way?

This is the code to open Form2 from Form1:
Private Sub cmdGravForm_Click()
On Error GoTo Err_cmdGravForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Form2"

stLinkCriteria = "[TGRAV_TMD_ID]=" & Me![TMD_ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog, Me![TMD_ID]

Where [TMD_ID] is Table1's primary key, and [TGRAV_TMD_ID] is Table2's field that tracks Table1's primary key.

On Form2 I've tried the following code that doesn't work:
Private Sub Form_Open(Cancel As Integer)
Me!TGRAV_TMD_ID.DefaultValue = OpenArgs
End Sub


Thanks,
Jim
 
Hmmm. I just noticed this will work if the tables are linked as one-to-many.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top