Fix Microsoft Access Search Button Not Working on Subform
Question details
The user needs to correct a VBA code issue where a search or filter button works perfectly on a standalone main form, but fails to execute when that same form is embedded as a subform.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Developing or troubleshooting a database interface where a search filter must be applied to records displayed inside a subform.
- Observed behavior
- The search button VBA code fails to apply the filter on the subform because standard form references do not account for the parent-child object hierarchy created by the subform control.
Verify the exact name of the subform container control on your main form, as this name often differs from the actual name of the source form object you are embedding. Always back up your Access database before modifying VBA code.
Update VBA Code to Explicitly Reference the Subform Control
Modify the VBA code behind the search button to route the filter command through the subform control's Form property on the parent form.
When a form is embedded inside another form, it becomes a child object of a subform control. Standard references like `Me.Filter` no longer apply directly because the code is executed from the context of the parent form. To resolve this, you must explicitly target the Form property of the subform control.
Right-click the main parent form in the Navigation Pane and select Design View.
Click once on the outer edge of the subform to select the container control. Press F4 to open the Property Sheet and note the exact text in the 'Name' property on the Other tab.
Right-click your search button on the main form, select Build Event, and choose Code Builder to open the VBA editor.
Update your filter string to reference the subform control. Use the syntax: `Me.[NameOfSubformControl].Form.Filter = "Surname LIKE ""*" & S & "*""` (replace 'NameOfSubformControl' with the name you found in step 2, and adjust the field name and variables as needed).
Add the command to turn the filter on immediately after your filter string: `Me.[NameOfSubformControl].Form.FilterOn = True`.
Save your VBA module, switch the parent form back to Form View, and click your search button to verify the subform filters correctly.

Looking for a Lightweight Office Suite? Try WPS Office
While WPS Office does not include a database management tool like Microsoft Access, it is an excellent free alternative for your daily document, spreadsheet, and presentation needs. It offers high compatibility with standard office files without the heavy subscription costs.
- 1. Download the installer: Visit the official WPS Office website and click the Free Download button for your operating system.
- 2. Install the software: Run the downloaded installer file and follow the simple on-screen instructions to complete the setup.
- 3. Open and edit your files: Launch WPS Office and directly open your existing Word, Excel, or PowerPoint documents with full formatting preserved.

Frequently Asked Questions
Why does my VBA code work on a standalone form but not as a subform?
When a form becomes a subform, its object hierarchy changes. It is now treated as a child object of the parent form's subform container control. Direct references like `Me.Filter` refer to the parent form, causing the code to fail.
How do I find the correct name of my subform control?
Open your main form in Design View, click once on the edge of the subform to select the container control, and press F4 to open the Property Sheet. Look at the 'Name' property on the Other or All tab. This is the name you must use in your VBA code.
Can I use macros instead of VBA to filter a subform?
Yes, you can use the ApplyFilter macro action. However, you still need to ensure the Control Name argument correctly targets the subform control's hierarchy so the database engine knows exactly where to apply the filter.




