Print to user selected printer without changing it to default???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spider1916
    New Member
    • Sep 2006
    • 9

    Print to user selected printer without changing it to default???

    I am using the common dialog control to allow my users to select any printer
    available to them. The code I am using keeps changing the selected printer
    to the default printer........ ....I don't want that.

    I can't find anything with a propar salution to my problem.
    I JUST WANT TO PRINT A REPORT!!!!!!!
    No setting needs to be changed, ever. I only want to get the selected printer
    from the dialog and print to it.

    This seems to allow me to print to the selected printer but still sets it as
    the default.

    Code:
        
        Dim X As Printer
        
        frmPO.comdPrintPO.ShowPrinter           
        
        For Each X In Printers
          
            If frmPO.comdPrintPO.hDC = X.hDC Then 
                
                Set Printer = X
       
            End If
        
        Next X
    System Specs:

    Win XP Pro
    Windows Visual Studio98
    Visual Basic 6.0

    Please reply.......... ...really need some help
    Thanks

    Spider1916
  • sashi
    Recognized Expert Top Contributor
    • Jun 2006
    • 1749

    #2
    Originally posted by spider1916
    I am using the common dialog control to allow my users to select any printer
    available to them. The code I am using keeps changing the selected printer
    to the default printer........ ....I don't want that.

    I can't find anything with a propar salution to my problem.
    I JUST WANT TO PRINT A REPORT!!!!!!!
    No setting needs to be changed, ever. I only want to get the selected printer
    from the dialog and print to it.

    This seems to allow me to print to the selected printer but still sets it as
    the default.

    Code:
        
        Dim X As Printer
        
        frmPO.comdPrintPO.ShowPrinter           
        
        For Each X In Printers
          
            If frmPO.comdPrintPO.hDC = X.hDC Then 
                
                Set Printer = X
       
            End If
        
        Next X
    System Specs:

    Win XP Pro
    Windows Visual Studio98
    Visual Basic 6.0

    Please reply.......... ...really need some help
    Thanks

    Spider1916

    Hi there,

    Kindly refer to below attached code segment for further understanding, it basically change the selected printer as default temporarily, hope it helps. Good luck & Take care.

    Code:
    Public Function SetDefaultPrinter(ByVal DeviceName As String) As Boolean
        Dim prThis As Printer
    
        If Printers.Count > 0 Then
            '\\ Iterate through all the installed printers
    
            For Each prThis In Printers
                '\\ If the desired one is found
                If prThis.DeviceName = DeviceName Then
                    Set Printer = prThis
                    SetDefaultPrinter = True
                    '\\ Stop searching
                    Exit For
                End If
            Next prThis
    
        End If
    End Function

    Comment

    • spider1916
      New Member
      • Sep 2006
      • 9

      #3
      Hi Sashi

      Thanks 4 the reply and code....

      Ok, so basically once the user has chosen a printer it should be set as the
      default. Then I Print the report to that printer (which is now default).

      Is it somehow possible to record the default printer devicename before the user
      makes a selection and then after the report has printed reset the default printer
      to that recorded devicename?? i.a.w. only make selected printer default until
      report is printed and then (without user interaction) reset to previous default?

      How would I go about getting the default printer name from the common dialog or whatever other place possible before user changes it?

      Thanks again
      Spider1916

      Comment

      • DogsBollox
        New Member
        • Jan 2007
        • 2

        #4
        Hi Mate,
        not sure if you still need help but....

        a few years ago I struggled with this problem for weeks and eventually I wrote a small function that changes the default printer only for the job being sent, it is automatically changed back.

        The code is now on PSC

        http://www.planetsourc ecode.com/vb/scripts/ShowCode.asp?tx tCodeId=55941&l ngWId=1

        if this does not work email and I will send it over

        Comment

        • spider1916
          New Member
          • Sep 2006
          • 9

          #5
          Originally posted by DogsBollox
          Hi Mate,
          not sure if you still need help but....

          a few years ago I struggled with this problem for weeks and eventually I wrote a small function that changes the default printer only for the job being sent, it is automatically changed back.

          The code is now on PSC

          http://www.planetsourc ecode.com/vb/scripts/ShowCode.asp?tx tCodeId=55941&l ngWId=1

          if this does not work email and I will send it over
          thanx so so so so much

          it worked like a dream, for a moment i thought i was imagining thing but no....
          i was able to change it to fit my needs......

          thanx again
          spider1916

          Comment

          • harrylarenson
            New Member
            • Dec 2006
            • 3

            #6
            Originally posted by spider1916
            thanx so so so so much

            it worked like a dream, for a moment i thought i was imagining thing but no....
            i was able to change it to fit my needs......

            thanx again
            spider1916

            I have the same Problem , but I could not resolve it.
            Would you please Write your code that you have solved the problem ?

            When I am using the code for SetDefaultprint er Function still The default printer is keep changing as I select another printer in commondialog printer.

            Thanks.

            Comment

            • harrylarenson
              New Member
              • Dec 2006
              • 3

              #7
              I used The function as:

              Code:
              Dim defaultPrinter
              
              defaultPrinter = Printer.DeviceName
              
              SetDefaultPrinter (defaultPrinter)
              but the default is not changing in VB 6.

              Comment

              • Tecdec
                New Member
                • Apr 2012
                • 1

                #8
                Old Topic, but i got the same problem.. and solved with this:

                Initial Code: Always change selected printer to default
                Code:
                    CommonDialog1.CancelError = True
                    CommonDialog1.ShowPrinter
                By default common dialog change selected printer to default.
                Code:
                    CommonDialog1.CancelError = True
                    CommonDialog1.PrinterDefault = False 'This Line Stop it!
                    CommonDialog1.ShowPrinter

                Comment

                • AmmarDev
                  New Member
                  • May 2016
                  • 2

                  #9
                  hi,

                  i send you an email so you can give a solution?

                  Comment

                  • mukilan89
                    New Member
                    • Aug 2018
                    • 1

                    #10
                    link expired

                    Can you send me the code. The link is expired.

                    Comment

                    Working...