logo
search
Others

How to Filter an Access Query Using Multiple Checkboxes

John WilsonJohn Wilson Oct 7, 2026 869 views

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.

How to Filter an Access Query Using Multiple Checkboxes
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.
Before you start

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.

Solution 1Recommended

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.

1
Add a Command Button

Open your Access form in Design View and add a Command Button that users will click to run the query.

2
Open the Code Builder

Right-click the new button, select 'Build Event', and choose 'Code Builder' to open the VBA editor.

3
Evaluate the Checkboxes

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.

4
Construct the SQL Statement

Remove the trailing comma from your string, then build the SQL statement using the IN operator: strSQL = "SELECT * FROM YourTable WHERE NameField IN (" & strWhere & ")".

5
Apply the Filter

Use the generated strSQL variable to either redefine a QueryDef or set it as the RecordSource for a subform or report.

Build a Dynamic SQL Query Using VBA
Handling No Selections: Always include an If statement in your VBA code to check if strWhere is empty before running the query, ensuring you handle cases where the user clicks the button without selecting any checkboxes.
Free Microsoft Office alternative

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.

Easily filter multiple criteria using built-in Data Filters without requiring complex VBA scripts.Fully compatible with Microsoft Excel (.xlsx, .xls) and CSV formats for seamless data migration.Lightweight software that installs quickly and runs smoothly on both modern and older devices.Familiar tabbed interface that makes organizing and analyzing tabular data simple.
microsoft office alternative - wps office

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