Others

How to Pass a Variable to Access DoCmd.OpenReport Using OpenArgs

John WilsonJohn Wilson Nov 4, 2026 869 views

Question details

The user needs to pass a variable via the OpenArgs parameter when opening a Microsoft Access report and utilize that variable to filter the report data.

How to Pass a Variable to Access DoCmd.OpenReport Using OpenArgs
Product
Microsoft Access
Device & OS
not provided
Scenario
Opening a report in Microsoft Access using VBA DoCmd.OpenReport and attempting to dynamically filter the output using a passed variable.
Observed behavior
Passing a value through the OpenArgs argument does not automatically filter the report; the report opens but ignores the intended filter unless handled by specific code.
Before you start

Ensure you have basic familiarity with Microsoft Access VBA and have opened your Access database in Design View to modify the report's code module.

Solution 1Recommended

Apply Filter Using OpenArgs in the Report's Open Event

Write VBA code in the report's On Open event to read the passed OpenArgs variable and actively apply it as a filter.

Passing a variable via OpenArgs does not automatically filter the record source by default. You must explicitly catch this variable in the report's VBA module and set the filter properties manually.

1
Pass the Variable

In your form's VBA code, pass the variable using the OpenArgs parameter: DoCmd.OpenReport "YourReportName", , , , , "YourVariableValue".

2
Open Report Design View

Navigate to the target report, right-click, and select Design View. Open the Property Sheet, go to the Event tab, and click the ellipses (...) next to 'On Open' to launch the VBA editor.

3
Add Filtering Code

Insert the following VBA code to read Me.OpenArgs: Dim strOpenArgs As String strOpenArgs = Nz(Me.OpenArgs, "") If Len(strOpenArgs) > 0 Then Me.Filter = "[YourFieldName] = '" & strOpenArgs & "'" Me.FilterOn = True End If

4
Save and Test

Save the VBA module and the report. Trigger the DoCmd.OpenReport action again to see the filtered results.

Apply Filter Using OpenArgs in the Report's Open Event
Handling Null Values: Always use the Nz() function when reading OpenArgs to prevent runtime errors if the report is ever opened without a passed variable.
Free Microsoft Office alternative

Need a Reliable Office Suite? Try WPS Office

While WPS Office does not feature a database tool like MS Access, it is an outstanding free alternative for Word, Excel, and PowerPoint files. Enjoy high format compatibility, a lightweight installer, and a familiar interface for your daily document tasks.

  1. 1. Download the Installer: Visit the official WPS Office website and click the free download button.
  2. 2. Install WPS Office: Run the setup file and follow the on-screen prompts for a fast installation.
  3. 3. Work with Office Files: Open, edit, and save your existing Word, Excel, and PowerPoint documents seamlessly.
Fully compatible with Microsoft Excel, Word, and PowerPoint formats.Lightweight and fast to launch on Windows, Mac, and mobile devices.Familiar tabbed interface requiring zero learning curve.Built-in PDF editing and conversion tools for better document management.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my Access report ignoring the OpenArgs parameter?

By default, Microsoft Access does not automatically apply OpenArgs as a data filter. You must explicitly write VBA code in the report's On Open event to read Me.OpenArgs and assign it to the Me.Filter property while setting Me.FilterOn = True.

Can I use OpenArgs to pass multiple variables to a report?

Yes, you can pass multiple values by concatenating them into a single string separated by a specific delimiter (like a pipe | or comma). In the report's Open event, you can use the Split() function in VBA to extract and assign the individual values to your filter string.

Is it better to use OpenArgs or a query reference to filter an Access report?

It depends on your workflow. OpenArgs is excellent for flexible, on-the-fly filtering driven entirely by VBA. However, if you are exporting the report to a PDF using DoCmd.OutputTo, using a query with criteria referencing an open form control (e.g., =Forms!FormName!ControlName) is often more reliable.