PDF output cancelled error 2501 (1 Viewer)

Pavl

Registered User.
Local time
Today, 23:04
Joined
Jan 17, 2013
Messages
56
Having read posts including those by "GemmaTheHusky" about this issue and followed the advice given I am still stuck.
"Enthusiastic beginner" with Access 2010 on Win7u.
Have been using this line behind command button with complete success between Dec'15 and Aug'16
Code:
DoCmd.OutputTo acOutputReport, "rpt_liberatorbycrew", acFormatPDF, "B24crew_" & FileNamePartTwo & ".pdf", False
Report opens and PDF is saved (always successful).
The concatenated filename "FileNamePartTwo" has no spaces and no special characters and has always been 7 text characters from text fields.

Recently just get the report to open (correct display without errors) but every use of the command button to instigate the above line fails with error 2501 and the above line highlited.
Have tried -
Removing underscores from the concatenated filename, replacing with hyphen, removing that to no character, removing first part (B24crews) - all without success.
Have returned to older backups including those prior to the date of full function.
All now fail with error 2501 - having previosly worked correctly.
There is no preexisting version of the desired filename in the destination folder (previous versions moved out).
BUT - by right click on open report I can go to Print Preview then save as PDF and get a correct copy as PDF.
 

MarkK

bit cruncher
Local time
Today, 15:04
Joined
Mar 17, 2004
Messages
8,178
What happens if you just open the report...
Code:
DoCmd.OpenReport "rpt_liberatorbycrew", acViewPreview
 

Pavl

Registered User.
Local time
Today, 23:04
Joined
Jan 17, 2013
Messages
56
Thank you Markk.
I get an empty version of the report opening in print preview.
The only field visible is that of three concatenated fields from another form that is not currently open.
That form is the usual calling form for the report.
But by having the calling form open at default record the test form button with your code opens a correct report for that default record.
 

sneuberg

AWF VIP
Local time
Today, 15:04
Joined
Oct 17, 2014
Messages
3,506
What happens if you puts in a fixed file name like:

Code:
DoCmd.OutputTo acOutputReport, "rpt_liberatorbycrew", acFormatPDF, "[COLOR="Blue"]Test1.pdf[/COLOR]", False
 

Pavl

Registered User.
Local time
Today, 23:04
Joined
Jan 17, 2013
Messages
56
Thanks Markk.
Marvelous!
That works correctly.
PDF version of report is saved to usual folder with correct contents relating to the open form with a chosen record this time instead of the default.
So what is going wrong with my version then ?
 

MarkK

bit cruncher
Local time
Today, 15:04
Joined
Mar 17, 2004
Messages
8,178
Do you mean thanks sneuberg? What works correctly?
 

Pavl

Registered User.
Local time
Today, 23:04
Joined
Jan 17, 2013
Messages
56
Oops - sorry - thanks to sneuberg.

The code given by sneuberg generates a correct PDF version of the report in the normal folder - exactly as per my previous versions - except of course that the filename is now "Test1.pdf".

Incidently - I tested the first version from Markk and right clicked the print preview as opened to get to report view.
This showed a correct report for the correct record and also my own command buttons that previosly worked.
But clicking my "Save PDF" generated the 2501 error again.
 

sneuberg

AWF VIP
Local time
Today, 15:04
Joined
Oct 17, 2014
Messages
3,506
Then for some reason I believe Access thinks there is an open PDF with the name that
Code:
 "B24crew_" & FileNamePartTwo & ".pdf"

generates. Could it be open but not visible? I suggest checking the Task Manager to see in there are any Acrobat processes (Something like ArcoRd32.exe) before you run the code.
 

Pavl

Registered User.
Local time
Today, 23:04
Joined
Jan 17, 2013
Messages
56
Thank you sneuberg.
Am using Foxit for PDFs and this was open.
So closed and checked for task ended. No Adobe tasks running.
Changed record on calling form and hit the button for the report.
Opened as expected and tried "Save PDF" button.
This worked ............just as it used to.
This with the shortened filename that I had failed with earlier.

Then uncommented out the original line of code with the longer filename that included the underscore prefix.
Failed with error 2501.
Commented that out and went back to the shorter version without prefix.
That worked correctly again.

Will continue to test variations to see if I can find the limits.
 

Pavl

Registered User.
Local time
Today, 23:04
Joined
Jan 17, 2013
Messages
56
Update after some tests:
Now working in original fashion .......having tried variations in filename including underscore after the fixed prefix.
Also working with PDF application running.

So good news is that mine is working.
Bad news is that this is now functioning correctly with no modifications to the original code after trying variations and returning to original.

I therefore have no idea why this was failing.
Thank you to Markk and sneuberg for your help.
 

sneuberg

AWF VIP
Local time
Today, 15:04
Joined
Oct 17, 2014
Messages
3,506
Here's a function we use to make certain the file name doesn't contain illegal characters.


Code:
Public Function RemoveIllegalFileCharacters(strFileName As String) As String
 
strFileName = Replace(strFileName, "<", "")
strFileName = Replace(strFileName, ">", "")
strFileName = Replace(strFileName, ":", "")
strFileName = Replace(strFileName, """", "")
strFileName = Replace(strFileName, "/", "")
strFileName = Replace(strFileName, "\", "")
strFileName = Replace(strFileName, "|", "")
strFileName = Replace(strFileName, "?", "")
strFileName = Replace(strFileName, "*", "")
RemoveIllegalFileCharacters = strFileName
 
End Function
 

bsm2th

New member
Local time
Today, 18:04
Joined
Apr 19, 2020
Messages
4
Sounds like trouble with the filename. It works if you make it a simple text value.
Try getting "B24crew_" & FileNamePartTwo & ".pdf" out of the OpenReport line.

Put "Dim filename as String" at the beginning of the procedure, then
filename="B24crew_" & FileNamePartTwo & ".pdf" before the OpenReport line.

Then set a breakpoint on the OpenReport line and run the program. When you print, it will stop there. Putting the mouse on the variable name will show what is in it. I'll be willing to bet Microsoft doesn't like whatever is there for a filename.

Bob
 

Micron

AWF VIP
Local time
Today, 18:04
Joined
Oct 20, 2018
Messages
3,476
You might have to provide a compacted/zipped version of your db, or show the entire code because AFAIK, 2501 is a generic sort of error message. It applies to what you're doing as well as forms and reports. It usually implies that an operation was cancelled, and Access provides the type of object when it occurs, so it is not specific to pdf creation. For example, if you DoCmd to open a form and the opening form code causes cancellation of that event, you will raise that error in the calling form's code. You can get the same result by closing an opening form in a form's load event as well. IIRC, it might be the same error raised if a report has no data, which is why (I think) we have the report OnNoData event.
 

Users who are viewing this thread

Top Bottom