Others

How to Use DoCmd.OpenForm with Two Filter Criteria in MS Access

Elise WilliamsElise Williams Nov 3, 2026 870 views

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.

How to Use DoCmd.OpenForm with Two Filter Criteria in MS Access
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

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.

2
Construct the concatenated expression

Ensure the 'And' operator is inside the double quotes, while the variables are concatenated outside using the ampersand (&) operator.

3
Apply the text syntax

Update your code to the following syntax: DoCmd.OpenForm "CASE ENTRY FORM_All Cases", , , "[Status] = '" & Me.Combo9 & "' And [Country] = '" & Me.Combo103 & "'"

Syntax Tip: Using a single concatenated string ensures Microsoft Access correctly interprets both the field names and the selected text values.
Free Microsoft Office alternative

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. 1. Visit the official website: Navigate to the official WPS Office website on your browser.
  2. 2. Download the installer: Click the 'Free Download' button to get the setup file for your operating system.
  3. 3. Install and start working: Run the installer, follow the on-screen prompts, and start opening your Microsoft Office files instantly.
Fully compatible with Microsoft Excel (.xlsx), Word (.docx), and PowerPoint (.pptx) formats.Lightweight installation ensures fast startup and smooth operation, even on older computers.Familiar tabbed interface allows you to manage documents, spreadsheets, and PDFs in one single window.Rich library of free templates and built-in AI tools to accelerate your workflow.
microsoft office alternative - wps office

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.