Solved

checking printer status and pausing

Posted on 2002-03-12
9
134 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
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 50

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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 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