Use Microsoft Access VBA to Open and Print a Report
Question details
Open and print an Access report from a form button using VBA.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A report uses a select query as its record source, and the user wants to open it from a form.
- Observed behavior
- Opening the report runs its record-source query, so the query does not need to be executed separately.
Confirm that the report's Record Source property points to the intended select query and that the report name matches the name used in your VBA code. If the query refers to form controls, make sure the form is open and the required values are available.
Open the report from a form button with VBA
Use the button's Click event to preview the report or send it directly to the printer.
Open the form in Design View, select the button, and open its Property Sheet. On the Event tab, set On Click to [Event Procedure] and select the ellipsis button to open the VBA editor.
Inside the button's Click procedure, add: DoCmd.OpenReport "131_Fitness_Rpt", acViewPreview. Replace the report name if yours is different.
Save the form, switch to Form View, and click the button. Access opens the report in Print Preview and runs its record-source select query.
In Print Preview, use the Print command on the ribbon. To print directly instead of previewing, replace acViewPreview in the VBA command with acViewNormal.

Create and Print Office Documents with WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with compatible Office documents and printing them. Existing Word, Excel, and PowerPoint files can be opened for an easier transition. WPS Office does not run Access reports or fix Access VBA.

Frequently Asked Questions
Do I need to run the select query before opening the report?
No. If the select query is the report's Record Source, Access runs it when you open the report with DoCmd.OpenReport.
How do I send the report straight to the printer?
In the button's Click procedure, use DoCmd.OpenReport "131_Fitness_Rpt", acViewNormal. Replace the report name with your own.
Can I create the report button without writing VBA myself?
Yes. In the form's Design View, use the Button control wizard and choose an action to open a report.
What if the report query uses values from the form?
Keep the referenced form open and enter the required control values before clicking the report button. Access uses those values when it runs the report's record-source query.




