Save report as PDF (Access 2013)

HAP_Paul

New member
Local time
Yesterday, 18:40
Joined
Jan 12, 2015
Messages
7
Hi all,

Despite googling and searching for solutions for many days, I keep having a problem. I know it has been discussed before, but I cannot find a solution for my case. It is really driving me nuts.

One of the users of my application, reports an error when saving a report to pdf by VBA code. She’s using Access 2013, on Windows 8.1.
The error is “error 2501 outputto action was cancelled with access vb macro”

The VBA code is
StrReport = “RepInvoice”
StrDocumentName = “C:\Users\Mary\Documents\Access\Invoice.pdf”
DoCmd.OpenReport StrReport, acViewPreview
DoCmd.OutputTo acOutputReport, StrReport, "PDFFormat(*.pdf)", StrDocumentName, False
DoCmd.Close acReport, StrReport, acSaveNo

This errror occurs at the OutputTo line. This code is part of an user form with a button “save as PDF”.
When this code is run, the report is visible as an example (as meant to be) on the screen. The code stops at the OutputTo line.

When I use
DoCmd.OutputTo acOutputReport, StrReport, acFormatPDF, StrDocumentName,, False
the problem still exists.

I tried to save the report manually by Preview > Export > PDF. The preview is OK, saving as PDF results in the same error 2501.
This may lead to the conclusion that this problem is not caused by the VBA code.

I verified whether user write rights are OK, and whether a default printer is available. Both are OK.
The report consists of 1 page.

When this very same application is used with Access 2010, everything functions as expected.

Who has any idea about the cause and a possible solution?

Thanks in advance,

Paul
 
StrReport = RepInvoice
StrDocumentName = C:\Users\Mary\Documents\Access\Invoice.pdf

should
be

StrReport = "RepInvoice"
StrDocumentName = "C:\Users\Mary\Documents\Access\Invoice.pdf"
 
Yes, I know. In fact, it is already like that.
For some reason, during copying the code, the quotes have changed.
So, this is not the cause of the problem.
 
I thin the format is "PDF Format (*.pdf)" not "PDFFormat(*.pdf)" (note tha spaces).

If your file extension is *.accdb, just use acFormatPDF constant.

All the best!
 
No, I do not think the format should be "PDF Format (*.pdf)".
With "PDFFormat(*.pdf)", I do not get this error when this database (mde format) is used on an other machine.
Besides that, as I initially stated, I get the same error when exporting to PDF manually. So I do not think the cause is in the VBA code.
 
Hardcode another filename and folder for it - see if that works.

Do you have any error handling in your report code? If not then insert some and see if it yields anything. I think if something untoward happens there, then it sometimes might result in the eror you are getting.
 
Just tried
DoCmd.OutputTo acOutputReport, StrReport, "PDF Format (*.pdf)", StrDocumentName, False
Unfortunately without success. I get the same error message.
 
Last edited:
Open up the report and start to 'comment out' any event code, especially looking at any event code in OnFormat.

Do it step by step, comment out a portion of code, then try Preview > Export > PDF -- keep doing that until the report is coming up blank or exports. I think eventually you'll come to an offending line of code on the report.

Regards
Melt
 

Users who are viewing this thread

Back
Top Bottom