Set default printer
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 5 of 5

Thread: Set default printer

  1. #1
    Join Date
    Oct 2002

    Set default printer

    Dear All,

    I need to set a different printer dynamically when printing reports in the run time, i tried to use the following code, but it doesn't work for me, the debug screen shows it has been changed, but it still print to the default printer, it means does not change. can anyone help me with this?


    Private Sub setPrinter(Name As String)
        Dim prThis As Printer
        If Printers.Count > 0 Then
            For Each prThis In Printers
                If prThis.DeviceName = Name Then
                    Set Printer = prThis
                    Exit For
                End If
            Next prThis
        End If
    End Sub
    Last edited by Cimperiali; May 31st, 2003 at 05:51 AM.

  2. #2
    Join Date
    Jul 2000
    Milano, Italy

    Set default printer

    The code you used sets the default for the running Vb project only.
    If you need to change the default for external programs, you need a different kind of code:
    from Iouri (scroll down and see his second answer)

    have also a look here:
    Microsoft online How to:;EN-US;266767

    and here:

    Cesare Imperiali
    Last edited by Cimperiali; May 31st, 2003 at 05:56 AM. present time, using mainly Net 4.0, Vs 2010

    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    May 2003
    upstate NY

    setting default printer

    this code example is provided to you by me for learning purposes. You may use it in your own apps, or change it how ever you like. I provide NO WARRANTY at all with this code.

    Ok now that is out of the way, I wrote this for a Microsoft Access 2000 database, the code could be used in a VB application very easily. Most all the code could be ported over all the API calls ect..

    I hope this helps you in what ever project you are doing.

    William O'Malley
    Attached Files Attached Files

  4. #4
    Join Date
    Jan 2003
    Albany, NY


    If you're switching between printers to avoid the report writer's Page With error check this out
    Your code can only be as good as your algorithm.

  5. #5
    Join Date
    Jul 2002

    When dealing with printers you can accomplish pretty much everything you need to do by shelling out commands to the PrintUI dll. I've found it amazingly valuable when dealing with printers. It allows adding, removing, set properties, drivers, installing drivers, even displaying print queues and options to the user using the Windows dialog boxes that are used by the system. It's really useful to know about, and simple to use. More info is an older posting I made:

    Some people say 'The world is a very strange place'

    Compared to what?

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center