Hi,
I've set up a form that accesses the reports container and lists out specified reports. The User selects one of these reports and can either view it by clicking one button, or print it by clicking another. Since these reports might be run in multiples, I wanted the ability to print the reports without them becoming visible and allow the user the option to select multiple copies.
I've tried every which way I can to get this to work, but if I am only running one report, it prints out correctly. However, during testing, if I run a report using the "printout" method, the first time it runs correctly, then the second time it fails. The third time it runs correctly, then the fourth time it fails, etc. Can anyone tell me what I might need to do to reset everything so this does not happen? Why might it be happening?
In the interim, I've rewritten the code numerous times, and I've even tried putting the report in preview mode and setting echo off, instead of using the "normal" mode which only prints. I've tried using a loop instead of entering a number, and I get a different error.
Here's some code where "rpt" is a variable with the report name and "n" is a variable with the number:
DoCmd.OpenReport rpt, acViewPreview, , , acHidden
DoCmd.PrintOut , acPrintAll, , , n, True
Many times it fails on this line:
DoCmd.Close acReport, Rpt, acSaveNo
I've also tried this:
'Dim x As Integer
'x = 0
DoCmd.Echo False, "Printer is receiving commands"
'DoCmd.OpenReport rpt, acViewPreview, , , acHidden
' DoCmd.SelectObject acReport, rpt, no
'DoCmd.PrintOut , acPrintAll, , , n, True
' Do Until x = n
' rpt.Print
' x = x + 1
'Loop
DoCmd.Echo True
Any ideas? One thought I had was that during the "close" of the report, I have a routine that checks for other open forms and pulls up the main form if closed.
Can you help?
I've set up a form that accesses the reports container and lists out specified reports. The User selects one of these reports and can either view it by clicking one button, or print it by clicking another. Since these reports might be run in multiples, I wanted the ability to print the reports without them becoming visible and allow the user the option to select multiple copies.
I've tried every which way I can to get this to work, but if I am only running one report, it prints out correctly. However, during testing, if I run a report using the "printout" method, the first time it runs correctly, then the second time it fails. The third time it runs correctly, then the fourth time it fails, etc. Can anyone tell me what I might need to do to reset everything so this does not happen? Why might it be happening?
In the interim, I've rewritten the code numerous times, and I've even tried putting the report in preview mode and setting echo off, instead of using the "normal" mode which only prints. I've tried using a loop instead of entering a number, and I get a different error.
Here's some code where "rpt" is a variable with the report name and "n" is a variable with the number:
DoCmd.OpenReport rpt, acViewPreview, , , acHidden
DoCmd.PrintOut , acPrintAll, , , n, True
Many times it fails on this line:
DoCmd.Close acReport, Rpt, acSaveNo
I've also tried this:
'Dim x As Integer
'x = 0
DoCmd.Echo False, "Printer is receiving commands"
'DoCmd.OpenReport rpt, acViewPreview, , , acHidden
' DoCmd.SelectObject acReport, rpt, no
'DoCmd.PrintOut , acPrintAll, , , n, True
' Do Until x = n
' rpt.Print
' x = x + 1
'Loop
DoCmd.Echo True
Any ideas? One thought I had was that during the "close" of the report, I have a routine that checks for other open forms and pulls up the main form if closed.
Can you help?