Solved

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

Posted on 2003-10-28
8
374 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
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 160 total points
ID: 9635905
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now