Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access VBA: docmd.printout fails. how to fix?

Status
Not open for further replies.

AlienHost

Programmer
Jan 11, 2008
15
US
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?
 
Why are you opening it hidden and then doing the PrintOut? You can just use:

DoCmd.OpenReport rpt, acViewNormal

and it will print out.


Bob Larson
A2K,A2K3,A2K7,SQL Server 2000/2005,Crystal Reports 10/XI,VB6, WinXP, and Vista
Free Quick Tutorials and Samples:
 
Hi Bob,

I probably wasn't clear enough in my original explanation.

Some of the reports run input boxes from the "on open" event, which I don't want the user to have to fill out multiple times. I'm trying to print out multiple copies with one print command, which

DoCmd.OpenReport rpt, acViewNormal

doesn't allow for and doesn't do. If I run it in a loop, it will open the report repeatedly and the user will have to input data into the input boxes repeatedly. Also, I'd then end up with a lot of open reports, as I'm not sure my code in the close event for the report is not part of the problem.

The "printout" command does allow for multiple reports to be printed, but, as previously stated, it isn't working correctly for me.

Do you think that running the input boxes might somehow be interfering with the process?
 
Use a FORM to collect the applicable information and then use that to filter the reports. Using inputbox or parameter selects within queries do not lend a "professional" touch to the program anyway, so an input form will be much better. Plus, you get the added bonus of the users not having to input things multiple times for anything, they can enter the information once and if they choose to print again they don't have to reenter the info. Also, if they type something wrong they don't have to go enter the entire info again, they can just fix the typo.


Bob Larson
A2K,A2K3,A2K7,SQL Server 2000/2005,Crystal Reports 10/XI,VB6, WinXP, and Vista
Free Quick Tutorials and Samples:
 
Thanks Bob, but I don't want to use another form. These reports are to be printed out on the fly and the time to pull up two forms just would get in the way. It should work from code at a button push like anything else. All they're inputting is the year.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top