OpenReport Action

Description

The OpenReport action opens a report in Design view or Print Preview, or it prints the report immediately. You can also restrict the records that are printed in the report.

Setting

The OpenReport action uses the following arguments.

Action argument

Description

Report Name

The name of the report to open. The Report Name box in the Action Arguments section of the Macro window shows all reports in the current database. This is a required argument.

If you run a macro containing the OpenReport action in a library database, Microsoft Access looks for the report with this name first in the library database, then in the current database.

View

The view in which the report will open. Click Print (to print the report immediately), Design, or Print Preview in the View box. The default is Print Preview.

Filter Name

A filter that restricts the report’s records. You can enter the name of either an existing query or a filter that was saved as a query. However, the query must include all the fields in the report you are opening or have its OutputAllFields property set to Yes.


Action argument

Description

Where Condition

A valid SQL WHERE clause (without the word WHERE) or expression that Microsoft Access uses to select records from the report’s underlying table or query. If you select a filter with the Filter Name argument, Microsoft Access applies this WHERE clause to the filter.

To open a report and restrict its records to those specified by the value of a control on a form, use the following expression.

[fieldname] = Forms![formname]![controlname on form]

The fieldname argument is the name of a field in the underlying table or query of the report you want to open. The controlname on form argument is the name of the control on the form that contains the value you want records in the report to match.

Note The maximum length of the Where Condition argument is 256 characters. If you need to enter a more complex SQL WHERE clause longer than this, use the OpenForm method of the DoCmd object in Visual Basic instead. You can enter SQL WHERE clause statements of up to 32,768 characters in Visual Basic.


Remarks

The Print setting for the View argument prints the report immediately using the current printer settings without bringing up the Print dialog box. You can also use the OpenReport action to open and set up a report and then use the PrintOut action to print it. For example, you may want to modify the report or use the PrintOut action to change the printer settings before you print.

The OpenReport action is similar to clicking the Design button, the Preview button, or the Print command on the File menu in the Database window after selecting a report.

Note Tips

  • To print similar reports for different sets of data, use a filter or a WHERE clause to restrict the records printed in the report. Then edit the macro to apply a different filter or change the Where Condition argument.
  • You can select a report in the Database window and drag it to a macro action row. This automatically creates an OpenReport action that opens the report in Print Preview.

See Also

OpenReport Method.