Results 1 to 7 of 7

Thread: How to select or set default printer by code?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Location
    Bangkok, Thailand
    Posts
    4

    Question

    I want my program to have a combo box that contain all of system printer's name and allow users to choose the printer for their job. How can I code my program? I don't know about printer's object, functions or API to complete it!! Could someone help me please?
    Thank you.

  2. #2
    New Member
    Join Date
    Mar 2001
    Location
    United Kingdom
    Posts
    9
    Hi vboyvboy:

    The following code should help. However, there is ample information in the VB help on-line.

    Dim X As Printer
    For Each X In Printers
    Combo1.AddItem X.DeviceName
    Next

    Hope this helps
    Work To Live, Don't Live To Work

  3. #3
    New Member
    Join Date
    Mar 2001
    Location
    United Kingdom
    Posts
    9
    Hi vboyvboy:

    Sorry about my last reply.

    Using the same code you can then set the either the default printer using the

    SET

    key word

    or you can use the name string to point your application to the printer you wish to use. As far as I know, this will only work if networked printers are set up in the domain inwhich the application is operating.
    Work To Live, Don't Live To Work

  4. #4
    New Member
    Join Date
    Oct 1999
    Location
    Charleston, SC USA
    Posts
    6
    There are several ways to to it

    Take a look at this
    Private Sub Command1_Click()
    Dim prtLoop As Printer
    'Dim Defaultprinter As Printer
    'Dim DefaultPrinterConstants As PrinterConstants
    'Dim DefaultPrinterName As String

    For Each prtLoop In Printers
    With prtLoop
    MsgBox "Device name: " & .DeviceName & vbCr & "Driver name: " & .DriverName & vbCr & "Port: " & .Port & vbCr & "Default:" & .TrackDefault
    End With
    Next prtLoop
    End Sub


    The DeviceName can vew used to pupulate the listbox of all your printers. Then you should (according to microsoft) set the printer by saying SET Printer ="<Printer Name>"

  5. #5
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179
    seeing what printers are installed and setting the default printer is all done through editing the registry. the vb ways of doing it are simple, but if like me you are in a fairly large organization you will find it a problem, the vb ways will not detect any more that 21 or 23 (cant quite remember) printers. If you read the information from the registry you can get all the details you need and then can write the printer that you want to be default into the string value that windows looks at for the default printer.
    Due to the energy crisis, the light at the end of the tunnel has been turned off.
    Sorry for any inconvenience this may cause

  6. #6
    New Member
    Join Date
    Oct 1999
    Location
    Charleston, SC USA
    Posts
    6
    Should it be that complicated?

  7. #7
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179
    if you can read and write to the registry, its not complicated at all
    Due to the energy crisis, the light at the end of the tunnel has been turned off.
    Sorry for any inconvenience this may cause

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width