Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting Network/Local Printer List and Setting Default Printer In VB5 & NT

Posted on 1998-07-09
3
Medium Priority
?
258 Views
Last Modified: 2010-05-03
Can you please tell me how to get a local/network Printer list in VB5 under WIN/NT & WIN95 and Set the default printer tto one of those printers?
0
Comment
Question by:moisidis
[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
 

Expert Comment

by:MikeABB
ID: 1465342
Have you tried the Printers collection?  As long as the printers that you are searching for are installed on the machine, it should be in this collection.  The VB help file gives the following example:

The Printers collection enables you to query the available printers so you can specify a default printer for your application. For example, you may want to find out which of the available printers uses a specific printer driver. The following code searches all available printers to locate the first printer with its page orientation set to portrait, then sets it as the default printer:

Dim X As Printer
For Each X In Printers
      If X.Orientation = vbPRORPortrait Then
            ' Set printer as system default.
            Set Printer = X
            ' Stop looking for a printer.
            Exit For
      End If
Next

You designate one of the printers in the Printers collection as the default printer by using the Set statement. The preceding example designates the printer identified by the object variable X, the default printer for the application.

If this solves your problem, let me know and I'll resubmit this as an answer
0
 
LVL 6

Accepted Solution

by:
clifABB earned 400 total points
ID: 1465343
The following code will load a listbox with available printers and when double clicked will set that printer as default.

Place a Listbox on a form.
Add the following code to the form's load event:
Private Sub Form_Load()
  Dim prtTarget As Printer

  For Each prtTarget In Printers
    List1.AddItem prtTarget.DeviceName
  Next prtTarget
End Sub

In the listbox's double click event, place the following code:
Private Sub List1_DblClick()
  Dim prtTarget As Printer
 
  For Each prtTarget In Printers
    If prtTarget.DeviceName = List1.List(List1.ListIndex) Then
      Set Printer = prtTarget
      Exit For
    End If
  Next prtTarget
End Sub
(This code could also be placed in a button's click event)
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1465344
By the way, you might want to add the following code to the form's load event after the code in my answer.  It highlights the current default printer:

  Dim nCnt1     As Integer
  For nCnt1 = 0 To List1.ListCount - 1
    If Printer.DeviceName = List1.List(nCnt1) Then
      List1.ListIndex = nCnt1
    End If
  Next nCnt1

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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

721 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