?
Solved

Print to a selected printer in a cbo

Posted on 2003-02-28
3
Medium Priority
?
226 Views
Last Modified: 2010-05-01
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
Comment
Question by:dwaneos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Expert Comment

by:Sharper
ID: 8044639
Set Printer = Printers(n)

0
 
LVL 3

Accepted Solution

by:
QJohnson earned 400 total points
ID: 8045094
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
 
LVL 3

Expert Comment

by:QJohnson
ID: 8045104
oops... shouldn't be a "set" in that first statement after the declarations... simple assignment:
 
   PrFoundName = Printer.DeviceName

sorry

Q
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month8 days, 14 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question