Solved

How to temporarily change printer then back again.

Posted on 2002-05-18
9
306 Views
Last Modified: 2010-05-02
I want my app to temporarily change printer output to a specific printer (PDF Print Device) and then back to the original default printer on the system.
I will not know the default printer name in advance.
In a couple lines of code, how do I do it?
0
Comment
Question by:rbend
[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
  • 6
  • 2
9 Comments
 
LVL 12

Expert Comment

by:roverm
ID: 7018726
Change it in the registry:

Key : HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows
String : Device

The value here is the current default printer.
Change it here in code.

D'Mzzl!
RoverM

(btw: This is the key for W2000Pro. If it not exists on your machine just do a search in the registry for your current default printer. To verify: change the default and see if the key has changed.)
0
 

Author Comment

by:rbend
ID: 7018739
This may work, but this will be happening very frequently and I don't want to write code to search the registry and mess with that each time.
I will opt for a less intrusive answer to the problem.
Thanks.
0
 
LVL 12

Expert Comment

by:roverm
ID: 7018745
You don't have to write the code to search the registry.
If you have found it once, manually, you can use this key to alter it as many times as you would like!

Just read it back b4 changing it (else you can't reset it to the original value ;-) ).

I KNOW this will work, I've this way in several applications.

D'Mzzl!
RoverM
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 12

Expert Comment

by:roverm
ID: 7018748
(that is: "I've USED this ...." lol)
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7018757
you could do it this way:

Dim defaultPrinter as Printer

set defaultPrinter = Printer

For Each p In Printers
   If p.DeviceName = "Your PDF Printer" Then '' you could also use the port for comparison
      Set Printer = p
   End If
next

'' your default printer is now Your pdf printer
'' do what you need here

'' set Printer back to default
set Printer = defaultPrinter

0
 
LVL 12

Expert Comment

by:roverm
ID: 7018764
bobbit31:
Yep, that will work, IF the PDF device will use the vb printer object.
When I build my apps, the device wasn't used (by the DataReport.... duh!!)

D'Mzzl!
RoverM
0
 

Author Comment

by:rbend
ID: 7019044
roverm:
This app will be distributed to PC's without my knowledge and without me being able to find out the registry contents. Therefore, the app would have to do the hunting each time.
0
 
LVL 12

Expert Comment

by:roverm
ID: 7019461
Only if the PC have different OS than yours. But if you have no knowledge of them at all then I suppose it will be more difficult.

The key I provided is correct for WinNT, 2000 and XP systems (and maybe ME). The only difference with 95/98 is (AFAIK) that the subkey "Windows NT" should be "Windows".
Maybe worth trying ?

D'Mzzl!
RoverM
0
 
LVL 12

Accepted Solution

by:
roverm earned 50 total points
ID: 7019527
And try this:

http://www.freevbcode.com/ShowCode.Asp?ID=641

D'Mzzl!
RoverM
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

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