How to Automatically Add a Main Form Value to an Access Subform
Question details
The user needs a method to automate data entry by passing an assigned person's value from a main form directly into a related subform's underlying table.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Assigning a task owner on a main form and needing that same person to automatically appear in a collaboration resources subform.
- Observed behavior
- Users frequently forget to manually add the main task owner to the collaborators subform, resulting in incomplete resource tracking.
Ensure you have a complete backup of your Microsoft Access database before modifying VBA code or running SQL queries. You should also verify the exact names of your primary key, foreign keys, and form controls to ensure the VBA code references the correct fields.
Use VBA and SQL in the After Update Event
The most reliable method is to execute an SQL INSERT statement via VBA when the main form is updated, directly appending the record to the subform's underlying table.
Instead of trying to manipulate the subform control directly, you can insert the new record directly into the underlying table for the subform. Once the record is added via SQL, requerying the subform will make the new record instantly visible.
Right-click your main form in the navigation pane and select 'Design View'.
Select the field control that triggers the assignment (e.g., 'Assigned To'). Open the Property Sheet, go to the 'Event' tab, click on 'After Update', and click the ellipsis (...) to open the Code Builder.
In the VBA editor, type the SQL execution command. For example: DoCmd.RunSQL "INSERT INTO tblCollaborationResources(FKtoMainTable, FKtoResources) VALUES(" & Me.MainID & "," & Me.AssignedTo & ")"
Add a line directly below the SQL command to refresh the subform data. Type: Me.YourSubformControlName.Requery (replacing 'YourSubformControlName' with the actual name of your subform control).

Set a Default Value for the Subform Field
If you simply want new subform records to automatically default to the main form's assigned person when a user starts typing, you can link the default value property without using SQL.
Looking for a Free Alternative to Microsoft Office?
While Microsoft Access is a specialized database tool, your daily document, spreadsheet, and presentation needs might not require an expensive subscription. WPS Office provides a lightweight, highly compatible, and free alternative to Word, Excel, and PowerPoint.
- 1. Download WPS Office: Visit the official WPS website and download the free installation package for your operating system.
- 2. Install the Software: Run the downloaded installer and follow the quick on-screen instructions to set up WPS Office.
- 3. Open Your Files: Launch WPS Office and seamlessly open your existing Microsoft Office documents, spreadsheets, and presentations.

Frequently Asked Questions
Why isn't my subform updating after running the VBA code?
You must refresh or requery the subform after the SQL INSERT statement executes. Add 'Me.YourSubformControlName.Requery' to your VBA script to force the subform to fetch the newly added record from the underlying table.
Can I prompt the user before automatically inserting the record into the subform?
Yes, you can add a 'MsgBox' function in your VBA code with a 'vbYesNo' prompt to ask the user if they want to add the task owner to the collaborators list before executing the 'DoCmd.RunSQL' statement.
What happens if the main form value is left blank when the VBA runs?
Running the SQL query with a null value may cause an error. You should wrap your VBA code in an 'If Not IsNull(Me.AssignedTo) Then' check to prevent runtime errors from firing when the field is empty.




