Others

Fix Access 2010 Error 2059 When Closing an Exported Report

Phi Hung VoPhi Hung Vo Nov 27, 2026 868 views

Question details

Correct the VBA code that closes an Access report after exporting it to PDF.

Fix Access 2010 Error 2059 When Closing an Exported Report
Product
Microsoft Access 2010
Device & OS
not provided
Scenario
A VBA procedure exports an Access report to PDF and then closes the report.
Observed behavior
The PDF export succeeds, but closing the report raises runtime error 2059 because the Close command references a different report name.
Before you start

Find the report's exact name in the Access Navigation Pane and open the VBA procedure that exports it. Confirm that the report is open before the Close command runs.

Solution 1Recommended

Match the Report Name in the OutputTo and Close Commands

Use the same report name for the PDF export and the command that closes the open report.

1
Open the VBA procedure

In Access, press Alt+F11 to open the Visual Basic Editor, then locate the procedure containing DoCmd.OutputTo and DoCmd.Close.

2
Compare the report names

Check the report name passed to DoCmd.OutputTo against the name in DoCmd.Close. Replace the Close command's name with the exact name of the open report being exported.

3
Use one name in both commands

For example, define a reportName variable and use it in both commands: Dim reportName As String reportName = "R006: Vessel in Transit" DoCmd.OutputTo acOutputReport, reportName, acFormatPDF, "C:\Reports\Vessel.pdf" DoCmd.Close acReport, reportName Replace the example report name and PDF path with your own, and ensure the destination folder exists.

4
Test the export

Run the procedure from Access and confirm that the PDF is created and the open report closes without error 2059.

Match the Report Name in the OutputTo and Close Commands
Check that the report is open: DoCmd.Close can close only a report that is open. If your procedure does not already open it, use DoCmd.OpenReport with the same report name before exporting and closing it.
Free Microsoft Office alternative

Create and Export Office Documents to PDF with WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for working with compatible Office documents and exporting them to PDF. It does not run Access databases or fix Access VBA errors, but it can help you migrate compatible documents and spreadsheets into an easy-to-use workspace.

Export supported documents and spreadsheets to PDFOpen and edit compatible Microsoft Word DOCX and Excel XLSX filesUse a familiar interface for everyday office tasksMove compatible Office files into a lightweight workspace
microsoft office alternative - wps office

Frequently Asked Questions

Why does the PDF export work before error 2059 appears?

The OutputTo command can export the specified report successfully, while a later DoCmd.Close command fails if it names a different report that Access cannot find.

Where can I find the correct report name?

Look for the report in the Access Navigation Pane, then use that exact object name in both DoCmd.OutputTo and DoCmd.Close.

Does OutputTo automatically open the report for closing?

Do not rely on OutputTo to leave the report open. Make sure the report is open before calling DoCmd.Close; if needed, open it with DoCmd.OpenReport using the same report name.

Can WPS Office fix this Access VBA error?

No. Correct the report name in the Microsoft Access VBA procedure. WPS Office can work with compatible Word and Excel files and export supported files to PDF, but it does not run Access databases.