Fix Access 2010 Error 2059 When Closing an Exported Report
Question details
Correct the VBA code that closes an Access report after exporting it to PDF.

- 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.
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.
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.
In Access, press Alt+F11 to open the Visual Basic Editor, then locate the procedure containing DoCmd.OutputTo and DoCmd.Close.
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.
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.
Run the procedure from Access and confirm that the PDF is created and the open report closes without error 2059.

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.

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.




