Solved

checking printer status and pausing

Posted on 2002-03-12
9
133 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 49

Expert Comment

by:Ryan Chong
Comment Utility
See this if it's help:

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

regards,
ryancys
0
 
LVL 4

Expert Comment

by:trkcorp
Comment Utility
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
Comment Utility
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
 
LVL 4

Accepted Solution

by:
trkcorp earned 200 total points
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Expert Comment

by:trkcorp
Comment Utility
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
Comment Utility
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
Comment Utility
Fair enough. Sorry for the delay
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
Comment Utility
Moving to the paq

kb
Experts Exchange Moderator
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now