How to Filter an Access Form with OpenArgs or WhereCondition
Question details
The user wants to filter records in a Microsoft Access form immediately when it opens by passing a selected value (such as from a combo box) to the target form.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Opening a detail form from a main menu or list, and ensuring it only displays the record matching a specific ID selected by the user.
- Observed behavior
- By default, a form opens displaying all records. The goal is to programmatically restrict the recordset to a specific ID upon initialization.
Ensure that the target form is bound to a table or query containing the field you wish to filter by (e.g., ContactID), and that you have identified the exact name of this field.
Method 1: Filter Using the WhereCondition Argument
This is the most straightforward method because it eliminates the need to write additional VBA code in the target form's module.
The DoCmd.OpenForm method includes a built-in parameter called WhereCondition. This acts identically to an SQL WHERE clause (without the word WHERE) and filters the form's recordset before it finishes loading.
Determine the value you want to filter by, such as the value from a combo box. You can assign this to a variable, for example: Dim intContactID As Integer, followed by intContactID = Me.cboContact.Value.
Add the command to open the form and pass the WhereCondition. The syntax looks like this: DoCmd.OpenForm "frmContacts", WhereCondition:="ContactID = " & intContactID. Replace 'frmContacts' and 'ContactID' with your actual form and field names.

Method 2: Pass Values via OpenArgs and Filter on Load
Use this method if you need to pass additional context or perform complex logic in the target form before applying the filter.
Looking for a Free Office Suite? Try WPS Office
While WPS Office does not include a database management tool like MS Access, it provides a powerful, free, and lightweight alternative for processing Word documents, Excel spreadsheets, and PowerPoint presentations with high compatibility and a familiar interface.
- 1. Download WPS Office: Visit the official WPS website and download the free installer.
- 2. Install the Software: Run the setup file and follow the quick installation prompts to get started.
- 3. Open Your Office Files: Instantly open and edit your existing .docx, .xlsx, and .pptx files with zero compatibility issues.

Frequently Asked Questions
What is the primary difference between WhereCondition and OpenArgs?
WhereCondition automatically filters the form's recordset upon opening without needing extra code. OpenArgs simply passes a string variable to the form, requiring you to write manual VBA code in the form's events (like On Load) to process that string and apply a filter.
Can I pass multiple values using OpenArgs?
Yes. Since OpenArgs accepts a single string, you can concatenate multiple values using a delimiter (such as a pipe '|' or a comma) when passing them. Inside the target form, use the VBA Split() function to break the string apart and assign the values as needed.
Why does my WhereCondition prompt for a parameter value instead of filtering?
This usually occurs if the field name specified in your WhereCondition string is misspelled or does not exist in the target form's underlying table or query. Ensure the field name in the condition exactly matches the field name in the database schema.




