Add an Access Form Button to Open the Filter Menu
Question details
Add a button to an Access form that opens the standard filter menu and restrict favorite records to the current user.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A form lets users select a user code and work with favorite records; the user also wants a button to open the filter menu.
- Observed behavior
- The filter menu needs the relevant control to have focus, and filtering favorites alone shows records for all users.
Open the form in Design View and identify the control to filter, the user ID control, and the field names in the form's record source. Confirm whether UserID is numeric or text, since the filter expression depends on its data type.
Set focus before opening the Access filter menu
Use this approach when a form button should open the standard filter menu for a specific control.
Open the form in Design View, add a Button from the Design tab, and select the new button.
In the Property Sheet, select the Event tab, set On Click to [Event Procedure], and click the ellipsis button to open the VBA editor.
In the button's Click procedure, add `Me!YourControlName.SetFocus` followed by `DoCmd.RunCommand acCmdFilterMenu`. Replace `YourControlName` with the name of the control whose filter menu you want to open.
Save the form, switch to Form View, and click the button. Confirm that the control can receive focus and that the filter command is available in the current view.

Filter favorites by the selected user's ID
Combine the Favorite and UserID criteria when the form currently shows favorites belonging to every user.
Manage Related Spreadsheet Data with WPS Office
WPS Office is a free, lightweight alternative for everyday office work, with a familiar interface and compatibility with common Microsoft Office files for a smoother transition. Use WPS Spreadsheets to filter tabular data; it does not replace Access forms or fix Access VBA commands.

Frequently Asked Questions
Why doesn't the filter menu open when I click the button?
The button may have focus instead of the field to filter. In the button's On Click event, call `SetFocus` on the relevant control before running `DoCmd.RunCommand acCmdFilterMenu`. Also check that filtering is available in the current form view.
How do I show favorites for just one user?
Set the form's Filter property to combine the Favorite and UserID conditions with AND, then set FilterOn to True. Ensure both fields are available in the form's record source.
What if UserID is a text field?
Text criteria need quotes around the value. In the VBA filter expression, surround the ID with single quotes and escape any embedded apostrophes, for example with `Replace(Me!cboUserID.Value, "'", "''")`.
How should I store favorites shared across many users and items?
Use a linking table containing user IDs and item IDs for the many-to-many relationship. In the form's record source, join that table to the user and item tables as needed, then filter on the linking table's user ID.




