Saving "Default" Printer, and putting it back later.

GregoryWest

Registered User.
Local time
Today, 15:37
Joined
Apr 13, 2014
Messages
161
I need to write some code. What I need to do is detect which printer the user has as their default printer. The nice thing is I do not really need this information for any of my tasks, other than to put the default back later. Then I need to change the default printer to a specific printer, print a report, then put the default back to what it was before. I have tried using the report tied to a specific printer, for a multiple number of reasons not worth going into that solution is a dead end.

So, in brief what I need to do is:
1. Save what the default printer is now.
2. Change the default printer to a specific printer.
3. Print a report.
4. Put the default printer back to the original default.

Anyone have an idea how I can do this?:banghead:
 
gregory. it isn't obvious. I can understand the headbanging. you do not actually need to know the name of the default printer to do this.

from memory

to set a specific printer (it may not need the set keyword)

set application.printer = printers("specific printer")

to restore the default, simply

set application.printer = nothing

now the only issue is that the printers object is a windows object, rather than access. and the printer name is case sensitive in this object

therefore many of us iterate the printers collection

Code:
 for each ptr in application.printers
    if ptr.name = requiredprinter then  'this test is not case sensitive
         set application.printer = ptr
         exit loop
   end if
 next
hope this helps

I imagine detecting the active printer requires a call to the windows api library, but there may be an access way.
 
Thanks for the reply. That helps quite a bit, the biggest issue is I will have no way of knowing that the users default printer is. And it will be different for different users. The code on changing the default printer to another printer is nice tho, was trying all sorts of other crap, none of which worked...
 

Users who are viewing this thread

Back
Top Bottom