Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

Print to a selected printer in a cbo

Does anyone know how I can print to specific printer in a combobox. I want to be able to print a report to a printer which I have selected in the cbo. It's reading the list of printers installed on my computer fine, I just need the code to actually print to that printer.

Need it kinda fast too...


Option Explicit
Dim Pr As Printer
-----------------

Private Sub cmdOK_Click()

?????????????

End Sub

Private Sub Form_Load()

For Each Pr In Printers
  cboPrinter.AddItem Pr.DeviceName
Next

End Sub

0
dwaneos
Asked:
dwaneos
  • 2
1 Solution
 
SharperCommented:
Set Printer = Printers(n)

0
 
QJohnsonCommented:
Looks like you've got the device name in the combo box, so:

Dim PrFoundName as String
Dim PrFind      as Printer

'    save a reference to the current default printer
set PrFoundName = Printer.DeviceName

For Each PrFind in Printers
   if PrFind.DeviceName = cboPrinter.Text then
      set Printer = PrFind          ' make it default
      exit for        '    no need to search any more
   end if         '   was this the one we're looking for?
Next       '       any more printers to check?

'   do your printing stuff here

'   now set it back the way you found it

For each PrFind in Printers
   if PrFind.DeviceName = PrFoundName then
      set Printer = PrFind
      exit for
   end if
Next

hth,

Q
0
 
QJohnsonCommented:
oops... shouldn't be a "set" in that first statement after the declarations... simple assignment:
 
   PrFoundName = Printer.DeviceName

sorry

Q
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now