Discussion:
OutputTo PDF error
(too old to reply)
septimus
2011-06-09 03:23:31 UTC
Permalink
I have a procedure that is intended to publish an Access report as a
PDF repeatedly, each time with the recordsource data changed.

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.
John Spencer
2011-06-09 13:15:16 UTC
Permalink
Have you tried adding a DoEvents and some delay in the loop?

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
Post by septimus
I have a procedure that is intended to publish an Access report as a
PDF repeatedly, each time with the recordsource data changed.
When I use the following line of code to publish the report to PDF a
DoCmd.OutputTo acOutputReport, "rptIAR", acFormatPDF, strPath
Trouble is, when I run the same line of code in the middle of a loop,
"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.
septimus
2011-06-09 15:36:59 UTC
Permalink
That doesn't seem to help because the error message comes up before
the program has a chance to move on to the "DoEvents" command.

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?
Post by John Spencer
Have you tried adding a DoEvents and some delay in the loop?
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
Post by septimus
I have a procedure that is intended to publish an Access report as a
PDF repeatedly, each time with the recordsource data changed.
When I use the following line of code to publish the report to PDF a
DoCmd.OutputTo acOutputReport, "rptIAR", acFormatPDF, strPath
Trouble is, when I run the same line of code in the middle of a loop,
"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.
Albert D. Kallal
2011-06-10 23:21:52 UTC
Permalink
Post by septimus
When I use the following line of code to publish the report to PDF a
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
***@msn.com
septimus
2011-06-11 01:36:46 UTC
Permalink
Post by Albert D. Kallal
Post by septimus
When I use the following line of code to publish the report to PDF a
DoCmd.OutputTo acOutputReport, "rptIAR", acFormatPDF, strPath
The above leaves the report open. Place a command to close the report, like
DoCmd.Close acReport,"rptIAR"
DoEvents
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
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
septimus
2011-06-11 02:25:07 UTC
Permalink
Post by septimus
Post by Albert D. Kallal
Post by septimus
When I use the following line of code to publish the report to PDF a
DoCmd.OutputTo acOutputReport, "rptIAR", acFormatPDF, strPath
The above leaves the report open. Place a command to close the report, like
DoCmd.Close acReport,"rptIAR"
DoEvents
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
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
    '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.
Tony Toews
2011-06-12 21:03:02 UTC
Permalink
On Fri, 10 Jun 2011 19:25:07 -0700 (PDT), septimus
Post by septimus
Found the problem. Turned out to be just an invalid character in the
file name.
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/
grovelli
2011-06-13 12:48:08 UTC
Permalink
Post by septimus
Post by septimus
Post by Albert D. Kallal
Post by septimus
When I use the following line of code to publish the report to PDF a
DoCmd.OutputTo acOutputReport, "rptIAR", acFormatPDF, strPath
The above leaves the report open. Place a command to close the report, like
DoCmd.Close acReport,"rptIAR"
DoEvents
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
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
    '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.- Nascondi testo citato
- Mostra testo citato -
What's the code for PopulateAnswerCounts and BuildFilePath?
Rachel Armendariz
2022-09-15 15:40:16 UTC
Permalink
Post by grovelli
Post by septimus
Post by septimus
Post by Albert D. Kallal
Post by septimus
When I use the following line of code to publish the report to PDF a
DoCmd.OutputTo acOutputReport, "rptIAR", acFormatPDF, strPath
The above leaves the report open. Place a command to close the report, like
DoCmd.Close acReport,"rptIAR"
DoEvents
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
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
'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.- Nascondi testo citato
- Mostra testo citato -
What's the code for PopulateAnswerCounts and BuildFilePath?
I am getting the same error and the file name is correct, trying to post a two page pdf in a folder and get the cancel 2501 error. Any suggestions. Works for all other reports except my two page report.
Loading...