How to Populate an Access Subform with a Main Form ID
Question details
The user needs to automatically populate a related foreign-key field in a Microsoft Access subform using an AutoNumber ID from the main form to ensure related tables update correctly.
- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Setting up a relational database form where a subform requires the main form's primary key to track related records.
- Observed behavior
- The related tables fail to update correctly when attempting to pass the AutoNumber value to the subform, especially when field data types are mismatched.
Ensure your main table and related sub-table have a properly established one-to-many relationship in the Database Tools tab before modifying form properties.
Configure Link Master and Link Child Fields
The most reliable way to populate a subform with a main form ID is to correctly link the Master and Child fields in the Subform control properties.
By defining the Link Master and Child fields, Access automatically passes the primary key from the main form to the foreign key of the subform for every new record created in the subform.
Right-click your main form in the navigation pane and select 'Design View'.
Click on the edge of the subform container to select it (ensure the Property Sheet shows 'Subform/Subreport', not the form inside it).
Press F4 to open the Property Sheet and navigate to the 'Data' tab.
Set 'Link Master Fields' to the AutoNumber ID field name of your main form, and set 'Link Child Fields' to the corresponding foreign-key field name in your subform.
Verify Data Types and Control Formats
Mismatched data types between the main form's primary key and the subform's foreign key will prevent automatic population.
Save the Main Record Before Data Entry
Access cannot pass a primary key to a subform if the main form's record has not been generated and saved.
Looking for a Lightweight Alternative to Microsoft Office?
While WPS Office does not include a relational database management tool like Microsoft Access, it offers a robust, free alternative for Word, Excel, and PowerPoint. If you frequently manage and analyze structured data using spreadsheets, WPS Spreadsheet provides powerful data tracking tools, pivot tables, and seamless compatibility with Microsoft Excel formats.
- 1. Download WPS Office: Visit the official WPS Office website and click the free download button for your operating system.
- 2. Install the Suite: Run the lightweight installer to equip your computer with Writer, Spreadsheet, Presentation, and PDF tools.
- 3. Manage Your Data: Export your database tables to CSV or Excel formats and open them effortlessly in WPS Spreadsheet for quick analysis.

Frequently Asked Questions
Why is my Access subform not updating with the main form ID?
This usually occurs if the 'Link Master Fields' and 'Link Child Fields' are not properly configured in the subform's Property Sheet, or if the main form record hasn't been saved to generate the AutoNumber before entering subform data.
Can I use an AutoNumber field for the foreign key in my subform?
No. While the primary key in the main table is an AutoNumber, the corresponding foreign key in the related child table must be set to a 'Number' data type with a Field Size of 'Long Integer'.
Should I delete the foreign key field from my subform to prevent user edits?
It is better practice to keep the foreign key control on the subform but hide it. You can do this by selecting the control in Design View, opening the Property Sheet, and changing the 'Visible' property to 'No'.
How do I handle multiple products per sale in Access?
You should use a continuous subform linked to a dedicated transaction table. Store the specific product details (like quantities and product IDs) in this related transaction table rather than duplicating them in the main sales form.




