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
Exit For
End If
Next prThis
End If
End Sub
Last edited by Cimperiali; May 31st, 2003 at 04:51 AM.
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) http://www.codeguru.com/forum/showth...hlight=printer
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.
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.
enjoy
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:
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.