When I use the following line of code to publish the report to PDF a
single time, it works:
DoCmd.OutputTo acOutputReport, "rptIAR", acFormatPDF, strPath
Trouble is, when I run the same line of code in the middle of a loop,
I get the following error:
"Run-Time error 2501: The OutputTo action was canceled"
It doesn't appear to be a problem with the report, it works fine when
I open it under the same conditions.
I can post at least some of the code if anyone thinks it would help,
but I won't do so now because it's lengthy.
Anybody encountered this problem? Solutions?
Thanks.
While Not .EOF
DoCmd.OutputTo acOutputReport, "rptIAR", acFormatPDF, strPath
DoEvents
sSleep 2000 'Sleep for two seconds
Wend
You can find the code for sSleep sub at
http://www.mvps.org/access/api/api0021.htm
John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
It says "Now Outputting 'rptIAR' to the file '[path].pdf'" and goes
through all pages of the report and then I get this "action canceled"
error.
Other ideas?
>When I use the following line of code to publish the report to PDF a
>single time, it works:
>DoCmd.OutputTo acOutputReport, "rptIAR", acFormatPDF, strPath
The above leaves the report open. Place a command to close the report, like
this:
DoCmd.Close acReport,"rptIAR"
DoEvents
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
Pleasenos...@msn.com
No, sorry, I think the way I phrased that was misleading. The report
never opens, so I can't close it using "DoCmd.Close". The first time
the code loop gets to the OutputTo command it says "Now Outputting
'rptIAR' to the file '[path].pdf'" and goes through all pages of the
report before I get the "action canceled" error.
What I meant when I said "When I use the following line of code to
publish the report to PDF a single time it works" is that if I place
that line of code (the OutputTo command) in a different procedure with
no loop, it works.
But in this context, it doesn't even matter what report I'm
outputting, I still get the "cancel" error. Why does Access think I'm
canceling the output?? Here's the code in case it helps:
'Start looping through records.
Do While Not rstGrouping.EOF
'Populate the recordsource of the report.
PopulateAnswerCounts "Interim", rstGrouping
'Build the path and file name of the PDF we're producing.
strPath = BuildFilePath("Interim", Me)
'Publish the report in PDF format.
DoCmd.OutputTo acOutputReport, "rptIAR", acFormatPDF, strPath,
False
rstGrouping.MoveNext
Loop
Found the problem. Turned out to be just an invalid character in the
file name. Thanks for your assistance.
Oh, now that's interesting. Thanks for posting the problem.
Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/
What's the code for PopulateAnswerCounts and BuildFilePath?