Fix Microsoft Access OutputTo Errors When Exporting Reports and Queries
Question details
Resolve an Access OutputTo error when exporting a report to PDF or a query to Excel.

- Product
- Microsoft Access 2010
- Device & OS
- not provided
- Scenario
- VBA code launched from a form exports a report and a query after running other queries. The code worked in Access 2007.
- Observed behavior
- Access 2010 reports that the command or action is not available when OutputTo runs. The query export can fail even when the PDF export is disabled.
Confirm the report and select query names in the Access Navigation Pane, and make sure the destination folder exists and is writable. Enable database content if Access displays a security warning that prevents VBA from running.
Open the report and query before exporting them
Use this approach when OutputTo fails because the objects are not open when the export runs.
Opening the select query before OutputTo resolved the reported query export issue. Open the report as well if you are exporting it to PDF, then close both objects after their exports.
In Access, press Alt+F11 and locate the form button's Click procedure or the module that runs the exports.
Before the report export, add DoCmd.OpenReport "ReportName", acViewPreview. Then call DoCmd.OutputTo acOutputReport, "ReportName", acFormatPDF, "C:\Exports\Report.pdf" and close it with DoCmd.Close acReport, "ReportName".
Before the query export, add DoCmd.OpenQuery "QueryName". Then call DoCmd.OutputTo acOutputQuery, "QueryName", acFormatXLSX, "C:\Exports\Query.xlsx" and close it with DoCmd.Close acQuery, "QueryName".
Replace ReportName, QueryName, and the example paths with your actual object names and existing destination paths. Run the button or procedure and check both output files.

Test each export and its destination separately
Use isolated tests to identify whether the report, query, event, or output path causes the error.
Work with exported Access query results in WPS Spreadsheets
WPS Office is a free, lightweight alternative with a familiar interface for working with exported spreadsheet files. Open an Excel export in WPS Spreadsheets to continue your work, though WPS does not fix Access VBA or run Access database exports.

Frequently Asked Questions
Why does the query export fail even when the PDF export is disabled?
The query export may have its own issue. Open the select query with DoCmd.OpenQuery before calling DoCmd.OutputTo, and test that export separately.
Do I need to create the export folder first?
Yes. Verify that the folder specified in each OutputTo path already exists and that you can write files to it.
Can closing the form affect the export procedure?
It can affect the code's execution context. Set a breakpoint on the OutputTo line in the VBA editor to confirm it is reached, and consider running the export before closing the form or moving the logic to a standard module.
Can WPS Office run the Access OutputTo command?
No. OutputTo is a Microsoft Access VBA command. After exporting the query to an Excel file in Access, you can open that file in WPS Spreadsheets.




