Click to See Complete Forum and Search --> : How to select or set default printer by code?
vboyvboy
Mar 24th, 2001, 04:37 AM
I want my program to have a combo box that contain all of system printer's name and allow users to choose the printer for their job. How can I code my program? I don't know about printer's object, functions or API to complete it!! Could someone help me please?
Thank you.
majnoon
Mar 27th, 2001, 11:41 AM
Hi vboyvboy:
The following code should help. However, there is ample information in the VB help on-line.
Dim X As Printer
For Each X In Printers
Combo1.AddItem X.DeviceName
Next
Hope this helps
majnoon
Mar 27th, 2001, 11:44 AM
Hi vboyvboy:
Sorry about my last reply.
Using the same code you can then set the either the default printer using the
SET
key word
or you can use the name string to point your application to the printer you wish to use. As far as I know, this will only work if networked printers are set up in the domain inwhich the application is operating.
Keptin
Apr 19th, 2001, 09:10 AM
There are several ways to to it
Take a look at this
Private Sub Command1_Click()
Dim prtLoop As Printer
'Dim Defaultprinter As Printer
'Dim DefaultPrinterConstants As PrinterConstants
'Dim DefaultPrinterName As String
For Each prtLoop In Printers
With prtLoop
MsgBox "Device name: " & .DeviceName & vbCr & "Driver name: " & .DriverName & vbCr & "Port: " & .Port & vbCr & "Default:" & .TrackDefault
End With
Next prtLoop
End Sub
The DeviceName can vew used to pupulate the listbox of all your printers. Then you should (according to microsoft) set the printer by saying SET Printer ="<Printer Name>"
aturner
Apr 20th, 2001, 06:27 AM
seeing what printers are installed and setting the default printer is all done through editing the registry. the vb ways of doing it are simple, but if like me you are in a fairly large organization you will find it a problem, the vb ways will not detect any more that 21 or 23 (cant quite remember) printers. If you read the information from the registry you can get all the details you need and then can write the printer that you want to be default into the string value that windows looks at for the default printer.
Keptin
Apr 20th, 2001, 08:09 AM
Should it be that complicated?
aturner
Apr 20th, 2001, 08:11 AM
if you can read and write to the registry, its not complicated at all
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.