Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OutputTo PDF error

2,738 views
Skip to first unread message

septimus

unread,
Jun 8, 2011, 11:23:31 PM6/8/11
to
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

unread,
Jun 9, 2011, 9:15:16 AM6/9/11
to
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

septimus

unread,
Jun 9, 2011, 11:36:59 AM6/9/11
to
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?

Albert D. Kallal

unread,
Jun 10, 2011, 7:21:52 PM6/10/11
to
"septimus" wrote in message
news:49a1b4ae-a663-48a4...@hd10g2000vbb.googlegroups.com...

>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

septimus

unread,
Jun 10, 2011, 9:36:46 PM6/10/11
to
On Jun 10, 6:21 pm, "Albert D. Kallal" <PleaseNOOOsPAMmkal...@msn.com>
wrote:
> Pleasenospam_kal...@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

septimus

unread,
Jun 10, 2011, 10:25:07 PM6/10/11
to

Found the problem. Turned out to be just an invalid character in the
file name. Thanks for your assistance.

Tony Toews

unread,
Jun 12, 2011, 5:03:02 PM6/12/11
to
On Fri, 10 Jun 2011 19:25:07 -0700 (PDT), septimus
<oveng...@yahoo.com> wrote:

>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

unread,
Jun 13, 2011, 8:48:08 AM6/13/11
to
> file name. Thanks for your assistance.- Nascondi testo citato
>
> - Mostra testo citato -

What's the code for PopulateAnswerCounts and BuildFilePath?

Rachel Armendariz

unread,
Sep 15, 2022, 11:40:20 AM9/15/22
to
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.
0 new messages