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

Thread: Set default printer

  1. #1
    Join Date
    Oct 2002
    Location
    Australia
    Posts
    207

    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?

    thanks
    Frankie

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Code:
    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 04:51 AM.

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    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)
    http://www.codeguru.com/forum/showth...hlight=printer

    have also a look here:
    Microsoft online How to:
    http://support.microsoft.com/default...b;EN-US;266767

    and here:
    http://www.codeguru.com/forum/showth...printer+system

    Cesare Imperiali
    Last edited by Cimperiali; May 31st, 2003 at 04:56 AM.
    ...at 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
    Location
    upstate NY
    Posts
    168

    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.
    enjoy


    William O'Malley
    Attached Files Attached Files

  4. #4
    Join Date
    Jan 2003
    Location
    Albany, NY
    Posts
    82

    Alternatively

    If you're switching between printers to avoid the report writer's Page With error check this out http://www.codeguru.com/forum/showth...hreadid=250928
    Your code can only be as good as your algorithm.

  5. #5
    Join Date
    Jul 2002
    Location
    Leeds
    Posts
    123
    Hi,

    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:

    http://www.codeguru.com/forum/showth...hreadid=220382

    Cheers,
    Angelus
    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 CodeGuru survey question.


Featured


HTML5 Development Center