Solved

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

Posted on 2003-10-28
8
377 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 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