Forum Discussion

itsmatta's avatar
itsmatta
Copper Contributor
Jun 19, 2024

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

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 record....it updates the table, but no linked ID now.

 

 

  • George_Hepworth's avatar
    George_Hepworth
    Silver Contributor
    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.

    • itsmatta's avatar
      itsmatta
      Copper Contributor

      George_Hepworth 

       

      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
  • > 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.

Resources