Subform updating table, but not when you open form individually to input data

Copper Contributor

I have an employee form connected to the employee table. I have a contacts form connected to the Contacts Table. When I drop in the Contact Form into the Employee form and type a few notes. It updates in the table and links the ID's together. If I create a button just to open the contacts form to modify on that employee's updates the table, but no linked ID now.




3 Replies
That's how forms and subforms are designed. They must work together. You should probably just stick to the original interface design approach using the Employee form with the subform.

> It updates in the table and links the ID's together.
Do you know why? Design the form, and inspect the subform properties on the Data tab: Link Master Fields and Link Child Fields are set, which allow Access to put the parent record's PK value in the child record's FK field.
If you have a standalone form, you don't get this benefit, but you could use code to add it.



I figured it out. First I had the ID missing on the other form. So when clicking the button to open the form, it couldn't find the correct employee ID. Second I added VBA to make this work successfully:

Option Compare Database
Option Explicit

Private Sub Contact_Click()
    DoCmd.OpenForm "ContactForm", , , "EmployeeID=" & EmployeeID
End Sub