How to Use DoCmd.OpenForm with Two Filter Criteria in MS Access
Question details
The user needs to construct a valid VBA string to open a form in Microsoft Access using DoCmd.OpenForm while applying two filter criteria simultaneously.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Filtering a database form based on multiple combo box selections, such as Status and Country.
- Observed behavior
- Placing the 'And' operator outside the quoted filter string causes a type mismatch or syntax error when executing the VBA code.
Verify the data types of the fields you are filtering by. Check if your combo boxes return plain text values or hidden numeric IDs from a lookup table, as this determines the correct quotation syntax for your filter string.
Format the Filter String for Text Values
Use this method when both combo boxes are returning plain text strings.
The filter string passed to DoCmd.OpenForm must be built as one complete, concatenated text expression. Text values inside the SQL string must be wrapped in single quotation marks.
Press Alt + F11 to open the VBA editor and locate the event procedure (e.g., a button click event) containing your DoCmd.OpenForm code block.
Ensure the 'And' operator is inside the double quotes, while the variables are concatenated outside using the ampersand (&) operator.
Update your code to the following syntax: DoCmd.OpenForm "CASE ENTRY FORM_All Cases", , , "[Status] = '" & Me.Combo9 & "' And [Country] = '" & Me.Combo103 & "'"
Format the Filter String for Numeric IDs
Use this method if your combo boxes use lookup tables and return hidden numeric IDs instead of text.
Use Explicit Bound Columns and Descriptive Names
Improve code reliability by explicitly referencing the correct column in your combo box.
Looking for a Free Office Suite? Try WPS Office
While Microsoft Access handles complex database management, WPS Office is an exceptional choice for all your document, spreadsheet, and presentation tasks. It is completely free, lightweight, and serves as the perfect productivity alternative to Microsoft Office.
- 1. Visit the official website: Navigate to the official WPS Office website on your browser.
- 2. Download the installer: Click the 'Free Download' button to get the setup file for your operating system.
- 3. Install and start working: Run the installer, follow the on-screen prompts, and start opening your Microsoft Office files instantly.

Frequently Asked Questions
Why do I get a 'type mismatch' error when filtering a form in Access?
A type mismatch usually occurs when you try to filter a numeric field with a text string, or vice versa. If your combo box relies on a lookup table and stores a numeric ID, you must remove the single quotation marks around the variable in your VBA filter string.
How do I filter a date field using DoCmd.OpenForm?
To filter by a date field in Access VBA, you must enclose the date variable with hash symbols (#) instead of single quotes. The syntax looks like this: "[OrderDate] = #" & Me.txtDate & "#".
Can I use more than two filter criteria with DoCmd.OpenForm?
Yes. You can chain as many criteria as needed by appending 'And' or 'Or' operators within your concatenated string. Just ensure that every text variable is wrapped in single quotes, date variables in hash tags, and numeric variables have no wrappers.




