Error 2501 on output to PDF

here4real

Registered User.
Local time
Today, 10:04
Joined
May 1, 2013
Messages
87
Access 2007. I can run the report for last month and with the VBA code outputting it directly to PDF and it works. When I run it for this month, I get an error 2501. This report has been running for months with no issues. When I run it for this month and preview the output, I can export it to PDF with no problems. Why can't I get it to work in VBA for this month?
 
Error 2501 associates with Cancelling the previous operation. Check the code again.
 
Happening on this line:

DoCmd.OutputTo acOutputReport, "Encounters by Location and Department - ALL", acFormatPDF, XFile

The OutputTo action was cancelled
 
As I said, it works fine for last month and was working fine for this month thru 3/11...
 
Since I can Preview and Export, is there a way to Export from a Print Preview using VBA???
 
That was already known. So are you hitting Cancel when the File Dialog appears?
 
No... The filename variable (XFILE) is constructed in the VBA... I know that works as it runs for last month...
 
Show the file name generated for last month and this month !
 
Filename for last month: 03-17-14 - ET Report 02-01-14 thru 02-28-14.pdf

Filename for this month: 03-17-14 - ET Report 03-01-14 thru 03-17-14.pdf
 
I don't mind using a workaround bandaid...

Since I can Preview and Export, is there a way to Export from a Print Preview using VBA??? That is, I can open the report with acViewPreview... How would I do an Export from there (if it is even possible)???
 
I would not aim for any band aids but sort out the cause, or else it might bite you again. Have you provided the entire path contained in XFILE? Have permissions changed? Disk space? If the file you are trying to write already exists and is open, I think you might get the same error.
 
Yes... Entire path is there... I inserted a breakpoint and ran it for both last month and this month and the value of XFILE was correct in both... No permission or disk space errors (I copied DB to local drive to see if anything there)... The file isn't open... Like I said - if I do a Print Preview of the report and then right-click export to the same filename it works... When I do an OutputTo PDF, it give me an error... Crazy...
 
I'm thinking of trying the Lebans method of outputting to PDF instead of OutputTo but would rather keep everything inside Access rather than external DLLs and 3rd party...
 
A little more info... When the VBA code generates the error (and I have the Print Preview window still open), if I right-click export to PDF the file created has all #ERROR for all of the fields (even though it had data in the Print Preview... However, if I End the debug and just display the report, then I CAN export it to PDF...

Note - the program creates a bunch of intermediate queries and tables that the report accesses...
 
I found the problem but I don't understand why it works sometimes and doesn't work other times. I was building the filename based on the contents of a field in the DB. Sometimes the field contains an apostrophe ('). I changed the filename to just a dummy name and it works fine now.
 
Thanks for guiding me in the right direction. I build a label with a colon in it and only when I saw your answer, about the apostrophe, I realized my mistake:)
 

Users who are viewing this thread

Back
Top Bottom