logo
search
Others

How to Filter an Access Form with OpenArgs or WhereCondition

Steve KSteve K Sep 27, 2026 870 views

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.

How to Filter an Access Form with OpenArgs or WhereCondition
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.
Before you start

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.

Solution 1Recommended

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.

1
Identify the filter value

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.

2
Execute DoCmd.OpenForm with WhereCondition

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 1: Filter Using the WhereCondition Argument
Simplicity: Because the filtering is handled entirely by the calling macro or VBA routine, the target form requires no custom On Load code and remains clean.
Free Microsoft Office alternative

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. 1. Download WPS Office: Visit the official WPS website and download the free installer.
  2. 2. Install the Software: Run the setup file and follow the quick installation prompts to get started.
  3. 3. Open Your Office Files: Instantly open and edit your existing .docx, .xlsx, and .pptx files with zero compatibility issues.
Completely free and lightweight Office suite for documents, spreadsheets, and presentationsSeamless format compatibility with Microsoft Word, Excel, and PowerPointFamiliar, tabbed user interface allowing for quick migration and easy navigationBuilt-in PDF editing capabilities for all your document needs
microsoft office alternative - wps office

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.