Solved

Setting Activeprinter (my problem is after "on" in the printer name)

Posted on 2003-10-28
8
378 Views
Last Modified: 2008-02-01
I have a drop down list that is populated with the names of all printers installed on the computer. I did this using a slightly modified version of the enumerate printers method microsoft describes here:
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q166/0/08.asp&NoWebContent=1
(I am using the PName strings to obtain the printer names)

The goal is to set the ActivePrinter to the one the user chooses from the list. My problem is that the enumerate printers method does not return the name of the printers' ports; thus, I cannot properly assign the activeprinter because I cannot complete the "on [port name]" portion.

Is there any way to retrieve the port names along with the printer names?
0
Comment
Question by:Shane_CU
[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
  • 4
  • 3
8 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9635816
Have you tried the printer object:

Private Sub Command1_Click()
Dim Prn As Printer
For Each Prn In Printers
    List1.AddItem Prn.DeviceName & vbTab & Prn.Port
Next
End Sub
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9635867
You could use something like this to change the active printer for your app:

Private Sub Form_Load()
Dim Prn As Printer
For Each Prn In Printers
    List1.AddItem Prn.DeviceName
Next
End Sub

Private Sub List1_Click()
SelectPrinter List1.List(List1.ListIndex)
MsgBox List1.List(List1.ListIndex) & " has been selected!"
End Sub

Private Function SelectPrinter(ByVal printer_name As String) As Boolean
Dim i As Integer
SelectPrinter = True
    For i = 0 To Printers.Count - 1
        If Printers(i).DeviceName = printer_name Then
            Set Printer = Printers(i)
            SelectPrinter = False
            Exit For
        End If
    Next i
End Function
0
 

Author Comment

by:Shane_CU
ID: 9635869
I am using VBA in Excel.  "Printer" does not appear to be a defined type.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 28

Accepted Solution

by:
vinnyd79 earned 160 total points
ID: 9635905
0
 

Author Comment

by:Shane_CU
ID: 9635977
vinny,
can't get that link to work
0
 

Author Comment

by:Shane_CU
ID: 9635985
nevermind.  got it working.
0
 
LVL 14

Expert Comment

by:aelatik
ID: 9636030
'try scripting object

    Dim WSNET, WSPRN As Object, I As Long
    Set WSNET = CreateObject("wscript.network")
    Set WSPRN = WSNET.EnumPrinterConnections
    For I = 0 To WSPRN.Count - 1 Step 2
        MsgBox WSPRN(I) & WSPRN(I + 1)
    Next I
    Set WSPRN = Nothing
    Set WSNET = Nothing
0
 

Author Comment

by:Shane_CU
ID: 9636045
wow.  this is a lot more involved than I initially intended.  But thanks to, VinnyD's link I can get it done.  I am having to use Microsoft's enumerate priters method in combination with the code that VinnyD gave me the link for!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

730 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