May 29th, 2003, 03:54 AM
Set default printer
I need to set a different printer dynamically when printing reports in the run time, i tried to use the following code, but it doesn't work for me, the debug screen shows it has been changed, but it still print to the default printer, it means does not change. can anyone help me with this?
Private Sub setPrinter(Name As String)
Dim prThis As Printer
If Printers.Count > 0 Then
For Each prThis In Printers
If prThis.DeviceName = Name Then
Set Printer = prThis
Last edited by Cimperiali; May 31st, 2003 at 04:51 AM.
May 31st, 2003, 04:50 AM
Set default printer
The code you used sets the default for the running Vb project only.
If you need to change the default for external programs, you need a different kind of code:
from Iouri (scroll down and see his second answer)
have also a look here:
Microsoft online How to:
Last edited by Cimperiali; May 31st, 2003 at 04:56 AM.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
May 31st, 2003, 01:00 PM
setting default printer
this code example is provided to you by me for learning purposes. You may use it in your own apps, or change it how ever you like. I provide NO WARRANTY at all with this code.
Ok now that is out of the way, I wrote this for a Microsoft Access 2000 database, the code could be used in a VB application very easily. Most all the code could be ported over all the API calls ect..
I hope this helps you in what ever project you are doing.
June 17th, 2003, 02:50 PM
If you're switching between printers to avoid the report writer's Page With error check this out http://www.codeguru.com/forum/showth...hreadid=250928
Your code can only be as good as your algorithm.
October 16th, 2003, 04:07 AM
When dealing with printers you can accomplish pretty much everything you need to do by shelling out commands to the PrintUI dll. I've found it amazingly valuable when dealing with printers. It allows adding, removing, set properties, drivers, installing drivers, even displaying print queues and options to the user using the Windows dialog boxes that are used by the system. It's really useful to know about, and simple to use. More info is an older posting I made:
Some people say 'The world is a very strange place'
Compared to what?
Click Here to Expand Forum to Full Width