Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restoring Default Printer

Status
Not open for further replies.

Becca999

Programmer
Oct 14, 2003
23
0
0
US
Hello,

I have several network printers that I need to print to based on what is going on in the application. I tried to create printer objects for each of the different printers and just do printerobject.print but that didn't work ... It creates the object with all of the properties of that printer but it just won't execute the Print or EndDoc methods. Now I am trying to store the default printer in an object, change Printer to which ever printer I need it to be then change it back. But there are two problems: 1. it changed the global object (I am calling it gDefaultPrinter) to the object I am trying to print to; 2. If you try to set the Printer object to a value the same as itself, it generates an error

I have in the Common module:
Global gErrorsPrinter As Printer
Global gDefaultPrinter As Printer

on start up:

'** Capture Default
Set gDefaultPrinter = Printer

'** Establish Errors printer
For Each cIn Printers
If TestPrt.DeviceName = gstrOverrideErrPrinter Then
Set gErrorsPrinter = TestPrt
Exit For '** Found it
End If
Next


This all seems to work fine. If I print devicenames in the immediate window they are all what I want them to be.

later, if there is an error I need to print

Set Printer = gErrorsPrinter
Printer.Print TXT
Printer.EndDoc
Set Printer = gDefaultPrinter

It fails on the last line and all 3 printer objects are the ErrorsPrinter.

If I do gErrorsPrinter.Print, I get object not supported errors.

Any ideas?

Thanks in adavance
 
I figured this out in case anyone is curious. I need to use the index of the Printers collection.

Printers(0) is the default printer.
When I loop through the printers looking for the Errors printer, I need to store its index in the global variable. When I need to print to that printer, I set the Printer objext to it, print then set it back:

Set Printer = Printers(gintErrorsPrinterIndex)
Printer.Print TXT
Printer.EndDoc
Set Printer = Printers(0)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top