Others

How to Automatically Add a Main Form Value to an Access Subform

Elise WilliamsElise Williams Oct 28, 2026 869 views

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.

How to Automatically Add a Main Form Value to an Access Subform
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Form Design View

Right-click your main form in the navigation pane and select 'Design View'.

2
Access the After Update Event

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.

3
Insert the SQL Command

In the VBA editor, type the SQL execution command. For example: DoCmd.RunSQL "INSERT INTO tblCollaborationResources(FKtoMainTable, FKtoResources) VALUES(" & Me.MainID & "," & Me.AssignedTo & ")"

4
Requery the Subform

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

Use VBA and SQL in the After Update Event
Preventing Errors: It is highly recommended to wrap your code in an 'If Not IsNull(Me.AssignedTo) Then' statement to prevent the SQL query from failing if the user clears the assigned field.
Free Microsoft Office alternative

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. 1. Download WPS Office: Visit the official WPS website and download the free installation package for your operating system.
  2. 2. Install the Software: Run the downloaded installer and follow the quick on-screen instructions to set up WPS Office.
  3. 3. Open Your Files: Launch WPS Office and seamlessly open your existing Microsoft Office documents, spreadsheets, and presentations.
Fully compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx).Lightweight design that runs smoothly on all devices without consuming heavy system resources.Familiar, intuitive user interface that requires zero learning curve for transitioning users.Free access to essential office tools in a single, tabbed workspace.
microsoft office alternative - wps office

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.