How to Pass a Parent ID to a New Access Subform Record
Question details
The user needs to automatically populate the Parent ID when creating a new record in a child form or subform opened via a button.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Opening a child form from a main parent form to add new related records.
- Observed behavior
- Existing records display correctly, but the parent ID field remains blank when attempting to add a new record.
Ensure you have the primary key (Parent ID) properly defined in your main table and a corresponding foreign key in your child table before attempting to link the forms.
Pass the Parent ID Using the OpenArgs Property in VBA
Best for opening a separate, large child form from a button on the parent form without embedding it.
When a child form is too large to fit as an embedded subform, you can open it as a separate popup. By utilizing the OpenArgs argument in the DoCmd.OpenForm method, you can seamlessly pass the current Parent ID to the newly opened form.
Open your main form in Design View. Right-click the button used to open the child form, select 'Build Event', and open the VBA editor for the On Click event.
Enter the following code to pass the ID: DoCmd.OpenForm "ChildFormName", , , , , , Me.ParentIDControlName
Open your child form in Design View. Go to the Property Sheet, select the 'Event' tab, and click the builder button (...) next to 'On Open'.
In the VBA editor, add this code to assign the passed ID to new records: If Not IsNull(Me.OpenArgs) Then Me.ChildForeignIDControl.DefaultValue = """" & Me.OpenArgs & """"

Use a Linked Subform for Automatic Inheritance
The easiest and most automated method if your main form has enough space to embed the child form directly.
Need a Lightweight Alternative for Your Daily Office Tasks?
While WPS Office does not include a direct database management equivalent to Microsoft Access, it offers a powerful, free, and highly compatible suite for your documents, spreadsheets, and presentations. Enjoy a familiar interface and seamless compatibility with Microsoft Word, Excel, and PowerPoint files without the heavy subscription costs.
- 1. Download the Installer: Visit the official WPS Office website and click the Free Download button.
- 2. Run the Installation: Open the downloaded executable file and follow the simple on-screen instructions.
- 3. Enjoy Free Office Tools: Launch WPS Office to easily open, edit, and save your Word, Excel, and PowerPoint documents.

Frequently Asked Questions
Why is my subform's Parent ID blank when I add a new record?
This usually happens if the form is opened independently via a button without passing the parent record's ID, or if the Link Master Fields and Link Child Fields properties are not properly defined in an embedded subform control.
What is OpenArgs in Microsoft Access?
OpenArgs is a property used in the DoCmd.OpenForm method that allows you to pass a string expression (such as a Parent ID) from one form to another when the second form is opened.
Can I pass multiple values using OpenArgs?
Yes, but you must concatenate them into a single string separated by a delimiter (such as a pipe '|' or a comma). You can then use the Split function in the receiving form's VBA code to separate and assign the individual values.




