We help IT Professionals succeed at work.

How do I know when the DoCmd.PrintOut command has finished?

623 Views
Last Modified: 2013-12-02
I'm using DoCmd.PrintOut acPrintAll to print a batch of reports to a postscript file and converting them to pdf using ghostscript.  I'm using the createprocessA API to shell out the ps2pdf utility and wait until the process has completed, but my problem is that I don't know how to wait for the DoCmd.PrintOut line to finish so sometimes the pdf that gets generated is blank because the ps2pdf utility is called before the .ps file has finished being generated.  Is there a way to check if the file is locked for writing still by the print call, or to tell me when the print job is done?  Right now I am just calling a wait function to pause for a few seconds hoping to give the print command enough time to finish, but this obviously is not very reliable or scalable for longer print jobs.
Comment
Watch Question

CERTIFIED EXPERT

Commented:
How about setting a global variable in the on close event of the form and watch the variable.  Or have code in the close event run the API.

Author

Commented:
I'm just now finding the printer APIs (VB6 examples), which if they work as stated, my problem will be solved.  Look at the links provided in the first response of this post: https://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21021919.html?query=print+wait+done&clearTAFilter=true

But this is going to be a lot of work.  I'll try putting the DoCmd.PrintOut line in the reports close event and see if the form stays open until the printing is done.

Author

Commented:
No, nevermind, I'd still be calling the same function, so I don't see how putting the print command in the close event would accomplish anything.
CERTIFIED EXPERT

Commented:
Just checking for the existence of the printer spool file will be straight forward and easy.  

I didn't say put the printout command in the report's close event.  I recommended moving the code to run the ps2pdf utility to the report close event.

Author

Commented:
I don't think moving the ps2pdf call would do anything for me becaue I'm already using the WaitForSingleEvent API to know when the shell thread has finished so this part isn't a problem for me.  Just the "Printing" is unreliable.   Checking the spool file sounds like something to try, though.  Where is this located?
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks for the posts, Nelson.

Author

Commented:
Nelson, I was tinkering and this worked well enough for me:  
https://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20305390.html?query=check+if+file+locked&topics=93
so I went with it since I'm printing directly to the file (not spooling - I figured it was an unneccessary step).  But your answer was still a good solution and addressed what I was asking so the points are rightfully yours.

Thanks for helping me out again.
CERTIFIED EXPERT

Commented:
Glad I was able to help.  Happy programming
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.