Link to home
Start Free TrialLog in
Avatar of DoughBoy
DoughBoy

asked on

checking printer status and pausing

Hi All,

I am trying to print a lot of Word 2000 documents using the folling code:

'keep looping until all printed
...
InvoiceObj.Selection.GoTo what:=-1, Name:="ContactTitleLastName"'InvoiceObj.Selection.Font.Bold = wdToggle
InvoiceObj.Selection.InsertAfter " " & sContactTitle & " " & sContactLastName
InvoiceObj.Selection.Font.Color = 0

InvoiceObj.Application.Visible = False
InvoiceObj.ChangeFileOpenDirectory App.Path & "\"
InvoiceObj.ActiveDocument.SaveAs FileName:="LetterTo" & sContactCompany & sContactTitle & sContactFirstName & sContactLastName & ".doc"

InvoiceObj.Application.PrintOut
InvoiceObj.quit
Set InvoiceObj = Nothing

...

Basically, I am opening a Word document, inserting some data, saving the doc as a different name, and then printing it.

2 problems occur. I get an error saying that a previous copy has been open, even though I closed it. Second, the printer does not like it when too many jobs come at once.

So, I would like to be able to wait until one print job is done before sending the next. AND I would like to be able to open the document and close it without any problems. The code within the ... gets repeated in a loop. Other code checks to make sure the file is NOT-read-only. It also, opens rather than creates the document.

Any ideas how to solve these two problems. Successful Working Sample code will get you the points.

TIA
DoughBoy
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

See this if it's help:

http://www.merrioncomputing.com/Programming/PrintStatus.htm

regards,
ryancys
Avatar of trkcorp
trkcorp

I would make a couple of suggestions... put a doevents in your loop, then maybe just create a pause by calling API Sleep occasionally to slow the thing down, ESPECIALLY BEFORE A NEW OPEN, and/or after a close - to allow the close operations to complete.  These may seem like too simple measures, but it sounds to me like you are just pushing too hard... Your docs aren't going to get off the printer any faster than the printer can print them and your program can certainly generate them much faster than the printer can print... I just think you need some breathing space for starters.
Avatar of DoughBoy

ASKER

Hi ryancys,
I am way too lazy (and often too dumb) to use API's.

Hi trkcorp,
I tried using doevents. That is the most dangerous line of code to use in VB. It makes my computer go crazy with all kinds of lockups.

Any other ideas?
Thanks for your concern.
ASKER CERTIFIED SOLUTION
Avatar of trkcorp
trkcorp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
From VB Help...
DoEvents Function:
Yields execution so that the operating system can process other events.
Syntax:
DoEvents( )

Remarks:
The DoEvents function returns an Integer representing the number of open forms in stand-alone versions of Visual Basic, such as Visual Basic, Professional Edition. DoEvents returns zero in all other applications.

DoEvents passes control to the operating system. Control is returned after the operating system has finished processing the events in its queue and all keys in the SendKeys queue have been sent.

DoEvents is most useful for simple things like allowing a user to cancel a process after it has started, for example a search for a file. For long-running processes, yielding the processor is better accomplished by using a Timer or delegating the task to an ActiveX EXE component. In the latter case, the task can continue completely independent of your application, and the operating system takes case of multitasking and time slicing.

Caution   Any time you temporarily yield the processor within an event procedure, make sure the procedure  is not executed again from a different part of your code before the first call returns; this could cause unpredictable results. In addition, do not use DoEvents if other applications could possibly interact with your procedure in unforeseen ways during the time you have yielded control.
Hi DoughBoy,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept trkcorp's comment(s) as an answer.

DoughBoy, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Fair enough. Sorry for the delay
DoughBoy,
You can finalize this yourself.  Jusr click the "Accept Comment as Answer" link that is next to the post.
-- Dan
Moving to the paq

kb
Experts Exchange Moderator