[RESOLVED] Print to selected printer
I am trying to select the printer from a listbox and printform.
the code:
Code:
Sub LoadPrinters()
Dim i As Integer
Dim lCount As Long
Dim p As Printer
lCount = Printers.Count
If lCount = 0 Then
Call MsgBox("No printer detected on this system", vbExclamation, App.Title)
End If
For Each p In Printers
lstPrinters.AddItem p.DeviceName
Next
Exit Sub
ErrHandler:
End Sub
How do i set the print to the listbox selected printer ?
Re: Print to selected printer
Wouldn't it be something as simple as: Printers(lstPrinters.ListIndex).hDC ?
or
Code:
Dim p As Printer
Set p = Printers(lstPrinters.ListIndex)
Re: Print to selected printer
No dim a printer, printer is a global device and it is usually identified by its devicename string
simply :
set Printer = List1.list(List1.ListIndex)
Re: Print to selected printer
Quote:
Originally Posted by
Navion
No dim a printer, printer is a global device and it is usually identified by its devicename string
simply :
set Printer = List1.list(List1.ListIndex)
True. Printer is a global property/class object. Should the need exist, one can create a separate instance by using the Printers collection
Though you should get a type mismatch if trying to set it to some cached devicename
Suggest instead: Set Printer = Printers(List1.ListIndex)
Re: Print to selected printer
thanks guys
Set Printer = Printers(List1.ListIndex)
this works