How to Filter an Access Query Using Multiple Checkboxes
Question details
The user needs to filter an Access query based on the selection of multiple checkboxes on a form, allowing the query to return records for all selected individuals.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Filtering query results dynamically via a user form populated with multiple checkbox controls.
- Observed behavior
- The query must evaluate which checkboxes are checked and return matching records for one or more selected names.
Ensure your form checkboxes are properly named and verify how the names are stored in your target table fields (e.g., as text strings or ID numbers) before writing your query logic.
Build a Dynamic SQL Query Using VBA
Use Visual Basic for Applications (VBA) to check which boxes are ticked and construct a dynamic WHERE string for your query.
When dealing with multiple optional criteria, building the SQL string dynamically using VBA is the most reliable and scalable approach. This prevents the query from becoming overly complex with nested logic.
Open your Access form in Design View and add a Command Button that users will click to run the query.
Right-click the new button, select 'Build Event', and choose 'Code Builder' to open the VBA editor.
Write VBA code to check each checkbox. For example: If Me.chkPersonA Then strWhere = strWhere & "'Person A'," Repeat this for each checkbox to build a comma-separated list of names.
Remove the trailing comma from your string, then build the SQL statement using the IN operator: strSQL = "SELECT * FROM YourTable WHERE NameField IN (" & strWhere & ")".
Use the generated strSQL variable to either redefine a QueryDef or set it as the RecordSource for a subform or report.

Use Query Criteria with IIf Functions
If you only have a small, fixed number of checkboxes, you can reference the form controls directly in the query design grid.
Manage Your Data Easily with WPS Spreadsheet
While Microsoft Access is a powerful database tool, complex form filtering often requires VBA coding. If you are tracking lists, assignments, or orders, WPS Spreadsheet offers an easier way to filter data without writing a single line of code. WPS Office is a free, lightweight suite that provides an intuitive interface for all your data management needs.

Frequently Asked Questions
Can I filter a query if no checkboxes are selected?
Yes. If you use VBA, you can modify your code to check if the criteria string is empty. Depending on your needs, you can either return all records by omitting the WHERE clause, or return no records by injecting a false condition like 'WHERE 1=0'.
How do I pass multiple selected values from a ListBox instead of Checkboxes?
A Multi-Select ListBox is often more scalable than multiple checkboxes. You can loop through the ItemsSelected collection of the ListBox in VBA to dynamically build the comma-separated IN ('A', 'B') string for your query.
Why is my query prompting for a parameter value when I run it?
This usually happens if the query cannot find the form control you referenced in the criteria. Ensure your form is open in Form View when running the query, and verify that the spelling of the form and control names exactly matches the reference, such as [Forms]![FormName]![ControlName].




