Solved

checking printer status and pausing

Posted on 2002-03-12
9
137 Views
Last Modified: 2011-10-03
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
0
Comment
Question by:DoughBoy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 6856992
See this if it's help:

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

regards,
ryancys
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6857014
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.
0
 

Author Comment

by:DoughBoy
ID: 6857153
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Accepted Solution

by:
trkcorp earned 200 total points
ID: 6857310
DB,
The sleep api is utterly simple, no fancy parameters or return codes:

Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

Delclare it in a module as public, or in a form as private.

Use like this:

Call Sleep(1000)

Where 1000 = 1000 milliseconds which is 1 second...
You can of course adjust that value up or down as required.
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6857325
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.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7618230
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
0
 

Author Comment

by:DoughBoy
ID: 7619424
Fair enough. Sorry for the delay
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7622239
DoughBoy,
You can finalize this yourself.  Jusr click the "Accept Comment as Answer" link that is next to the post.
-- Dan
0
 
LVL 1

Expert Comment

by:kodiakbear
ID: 7665637
Moving to the paq

kb
Experts Exchange Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question