How to Automatically Create an Access Parent Record from a Child Form
Question details
The user wants to automatically generate a parent record when entering data into a child form in Microsoft Access.
- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Designing an Access database form for data entry where users might attempt to input child records (like funding or grants) before the main parent record exists.
- Observed behavior
- Access returns an error because a subform depends on the parent record for its foreign key. Attempting to force parent record creation via VBA recordsets often results in invalid or duplicate records.
Verify your database relationships in the Access 'Database Tools' tab to ensure that one-to-many relationships are properly defined and referential integrity is enforced between your parent and child tables.
Configure Standard Master and Child Linked Fields
The recommended approach is to ensure the parent record is created and saved first, allowing Access to handle the foreign key relationship automatically through the subform's linked fields.
A subform fundamentally depends on the parent form for its foreign key. Because Access cannot logically predict which new parent record a child belongs to, the parent key must exist before child data is entered. Adhering to standard Access form design prevents data corruption and duplicate records.
Build your main form based on the parent table and your subform based on the child table.
Right-click your main form in the navigation pane and select 'Design View'.
Click once on the subform container to highlight it, then open the Property Sheet (F4).
Navigate to the 'Data' tab in the Property Sheet. Set 'Link Master Fields' to the parent table's primary key, and 'Link Child Fields' to the child table's foreign key.
To ensure users don't encounter errors, you can add a simple macro or VBA command (DoCmd.RunCommand acCmdSaveRecord) on the main form's 'On Lost Focus' event before they enter the subform.

Use VBA to Check and Create Parent Records
If your specific business logic dictates that child data must be entered first, you can use VBA to check for a parent record and create one if it does not exist.
Looking for a Lightweight and Free Office Suite?
While WPS Office does not include a database management tool like Microsoft Access, it is an exceptional, free alternative for handling all your everyday document, spreadsheet, and presentation tasks. If you frequently export Access reports to Excel, WPS Spreadsheet manages data analysis seamlessly.

Frequently Asked Questions
Why do I get an error saying a related record is required in Microsoft Access?
This error triggers when your database enforces referential integrity. It means you are trying to enter data into a child table via a subform, but the corresponding parent record hasn't been saved yet in the main form.
Can I force Microsoft Access to save the main form automatically?
Yes. A common practice is to place a save command on a button, or attach the VBA command `DoCmd.RunCommand acCmdSaveRecord` to the 'On Exit' or 'On Lost Focus' event of the last field in the main form before the user enters the subform.
Is it safe to use VBA to create parent records automatically?
It is generally not recommended unless your specific workflow demands it. Manually creating records via VBA bypasses the native form linkage and can easily result in duplicate parent records or database bloat if robust error handling isn't implemented.




