Changing Printers in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DAHMB
    New Member
    • Nov 2007
    • 147

    #1

    Changing Printers in VB

    Why won't this work? I am using access 2007.

    Code:
    Private Sub btnPrint_Click()
    Dim strDefaultPrinter As String
    
    ' get current default printer.
    strDefaultPrinter = Application.Printer.DeviceName
    
    ' switch to printer of your choice:
    
    Set Application.Printer = Application.Printers("Oce cm6520")
    DoCmd.PrintOut acPrintAll
    
    '   Swtich back.
    
    Set Application.Printer = Application.Printers(strDefaultPrinter)
    
    End Sub
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    What's going wrong when you run the code?

    Comment

    • DAHMB
      New Member
      • Nov 2007
      • 147

      #3
      I get a runtime error 5, invalid procedure call or argument

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by DAHMB
        Why won't this work? I am using access 2007.

        Code:
        Private Sub btnPrint_Click()
        Dim strDefaultPrinter As String
        
        ' get current default printer.
        strDefaultPrinter = Application.Printer.DeviceName
        
        ' switch to printer of your choice:
        
        Set Application.Printer = Application.Printers("Oce cm6520")
        DoCmd.PrintOut acPrintAll
        
        '   Swtich back.
        
        Set Application.Printer = Application.Printers(strDefaultPrinter)
        
        End Sub
        Try replacing Line #14 with:
        Code:
        'Reset the Default Printer back to the way it was 
        Set Application.Printer = Nothing

        Comment

        • DAHMB
          New Member
          • Nov 2007
          • 147

          #5
          I tried what you said and it did not work. I get the same error and when I click debug it highlights line 9.

          Comment

          • ChipR
            Recognized Expert Top Contributor
            • Jul 2008
            • 1289

            #6
            Are you sure the device name is correct? You can list them all with the code in How to: Retrieve a List of Installed Printers.

            Comment

            • missinglinq
              Recognized Expert Specialist
              • Nov 2006
              • 3533

              #7
              I believe that being unable to switch from the Default Printer to another printer is a known bug in 2007. Here's a link for the hotfix:



              Linq ;0)>

              Comment

              • DAHMB
                New Member
                • Nov 2007
                • 147

                #8
                I got it!! Apparently it is case sensative when it comes to the printers name. Thanks everyone.

                Comment

                Working...