![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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. |
#3
| |||
| |||
|
|
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 On 6/8/2011 11:23 PM, septimus wrote: 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. |
#4
| |||
| |||
|
|
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 |
#5
| |||
| |||
|
|
"septimus" *wrote in message news:49a1b4ae-a663-48a4-a9c2-1e482bc800b2 (AT) hd10g2000vbb (DOT) 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 Pleasenospam_kal... (AT) msn (DOT) com |
#6
| |||
| |||
|
|
On Jun 10, 6:21*pm, "Albert D. Kallal" <PleaseNOOOsPAMmkal... (AT) msn (DOT) com wrote: "septimus" *wrote in message news:49a1b4ae-a663-48a4-a9c2-1e482bc800b2 (AT) hd10g2000vbb (DOT) 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 Pleasenospam_kal... (AT) msn (DOT) 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 |
#7
| |||
| |||
|
|
Found the problem. Turned out to be just an invalid character in the file name. |
#8
| |||
| |||
|
|
On Jun 10, 8:36*pm, septimus <ovengra... (AT) yahoo (DOT) com> wrote: On Jun 10, 6:21*pm, "Albert D. Kallal" <PleaseNOOOsPAMmkal... (AT) msn (DOT) com wrote: "septimus" *wrote in message news:49a1b4ae-a663-48a4-a9c2-1e482bc800b2 (AT) hd10g2000vbb (DOT) 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 Pleasenospam_kal... (AT) msn (DOT) 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.- Nascondi testo citato - Mostra testo citato - |
![]() |
| Thread Tools | |
| Display Modes | |
| |