I have the following code to print to report to pdf
DoCmd.OpenReport strReportName, 2, , Wclause, acHidden
DoEvents
DoEvents
DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, FolderPath & "\" & strReportCommonName & ".pdf", False, , , acExportQualityPrint
DoCmd.Close acReport, strReportName, acSaveNo
I first open the report in hidden mode so that I can filter the records on the report
Occassionally I get an error code 2501 - "Action was cancelled" on line DoCmd.OutputTo.........
I thought it might be because the report is still opening in line DoCmd.OpenReport....... hence the DoEvents, but this does not help!
The funny thing thing is that the error is not constant.
I am testing on one report with the same data and criteria.
6 times out of 10 no error will occur!
When the error occurs and I select debug, the problematic code "DoCmd.OutputTo acOutputReport...." is highlighted in yellow.
If I hit F5 the code will eventually run! I may have to hit F5 a couple of times, but the code will run and the file will be created.
How can I automate a simillar action to hitting F5?
I need to get the report to file!
Thanks
DoCmd.OpenReport strReportName, 2, , Wclause, acHidden
DoEvents
DoEvents
DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, FolderPath & "\" & strReportCommonName & ".pdf", False, , , acExportQualityPrint
DoCmd.Close acReport, strReportName, acSaveNo
I first open the report in hidden mode so that I can filter the records on the report
Occassionally I get an error code 2501 - "Action was cancelled" on line DoCmd.OutputTo.........
I thought it might be because the report is still opening in line DoCmd.OpenReport....... hence the DoEvents, but this does not help!
The funny thing thing is that the error is not constant.
I am testing on one report with the same data and criteria.
6 times out of 10 no error will occur!
When the error occurs and I select debug, the problematic code "DoCmd.OutputTo acOutputReport...." is highlighted in yellow.
If I hit F5 the code will eventually run! I may have to hit F5 a couple of times, but the code will run and the file will be created.
How can I automate a simillar action to hitting F5?
I need to get the report to file!
Thanks