Restoring the default printer 
Author Message
 Restoring the default printer

I would like to allow my users to choose which printer to print to without changing the system default.  Alternatively, I'd like to restore the preexisting printer to the default after I've completed printing.  I regard changing the system default printer on the user to be poor behavior for an application.

I'm trying to print the contents of a RTF text box.  When the application ends, the system printer has switched to whatever the user picks and doesn't get restored.  Any suggestions?  This is what I'm trying:
Private Sub mnuFilePrint_Click()
Dim RegularPrinter As String
Dim oPrinter As Printer
   RegularPrinter = Printer.DeviceName
   Debug.Print RegularPrinter

   CmnDlg1.Flags = cdlPDReturnDC + cdlPDNoPageNums
   If rtfMain.SelLength = 0 Then
      CmnDlg1.Flags = CmnDlg1.Flags + cdlPDAllPages
   Else
      CmnDlg1.Flags = CmnDlg1.Flags + cdlPDSelection
   End If
   CmnDlg1.ShowPrinter

   Printer.Print ""
   rtfMain.SelPrint CmnDlg1.hDC
   For Each oPrinter In Printers
      If oPrinter.DeviceName = RegularPrinter Then
         Set Printer = oPrinter
         Printer.Print ""
         Debug.Print Printer.DeviceName
         Exit For
      End If
   Next oPrinter

End Sub



Sun, 23 Sep 2001 03:00:00 GMT  
 Restoring the default printer
Hi Elton:

Something like this should work:

   Dim DevName As String
   Dim prt As Printer

   DevName = Printer.DeviceName

   'add code here to change/select printer...
   'perform print job...

   For Each prt In Printers
      If prt.DeviceName = DevName Then
         Set Printer = prt
      End If
   Next prt

Hope this helps,

Doug.



Sun, 23 Sep 2001 03:00:00 GMT  
 Restoring the default printer
setting the printer won't work since this only affects the default printer
for that.  I had a similar problem and found some code snipet which
displayed the printer setup dialog and returned the value the values also.
let me know if you are interested.  Also the common dialog has a property
called "PrinterDefault" which when set to true modifies the default printer
and when set to false is useless to you.  Since the printer object reflects
the dafault printer

Quote:
> Hi Elton:

> Something like this should work:

>    Dim DevName As String
>    Dim prt As Printer

>    DevName = Printer.DeviceName

>    'add code here to change/select printer...
>    'perform print job...

>    For Each prt In Printers
>       If prt.DeviceName = DevName Then
>          Set Printer = prt
>       End If
>    Next prt

> Hope this helps,

> Doug.



Sun, 23 Sep 2001 03:00:00 GMT  
 Restoring the default printer
Hi Steele:

Quote:
>setting the printer won't work since this only affects the default printer
>for that.

I think you missed the point -- the code should *reset* the default printer
to what it was *before* the user changed it.
I believe that is what the original post asked about.

Doug.



Sun, 23 Sep 2001 03:00:00 GMT  
 Restoring the default printer
You would have to store the printer's devicename and then restore it after
the user closes the Printer setup dialog, since the common dialog changes
the default window's default when the Printerdefault property is set to
true.  What I was saying was that you could avoid all of that and use API
calls to display the printer setup dialog and not change the window's
default at all.  At the same time you would have the values from the dialog.

Quote:
> Hi Steele:

> >setting the printer won't work since this only affects the default
printer
> >for that.

> I think you missed the point -- the code should *reset* the default
printer
> to what it was *before* the user changed it.
> I believe that is what the original post asked about.

> Doug.



Mon, 24 Sep 2001 03:00:00 GMT  
 Restoring the default printer
Hi Steele:

Quote:
>You would have to store the printer's devicename and then restore it after
>the user closes the Printer setup dialog

Which was the point of my post :)

Quote:
>What I was saying was that you could avoid all of that and use API
>calls to display the printer setup dialog and not change the window's
>default at all.

I realize this, but I what I got from your post was that my way would not
work at all.

Doug.



Mon, 24 Sep 2001 03:00:00 GMT  
 Restoring the default printer
Steele,

I'm really very interested in the code you're talking about. I've had the
same problem in letting the user set a printer during the lifetime of the
application but I didn't want to change the default. I never got this up and
running quite the way I wanted.

So if you could send me the code samples of the API calls I'd be eternally
gratefull.

TIA
Friso Wiskerke


Quote:

>You would have to store the printer's devicename and then restore it after
>the user closes the Printer setup dialog, since the common dialog changes
>the default window's default when the Printerdefault property is set to
>true.  What I was saying was that you could avoid all of that and use API
>calls to display the printer setup dialog and not change the window's
>default at all.  At the same time you would have the values from the
dialog.


>> Hi Steele:

>> >setting the printer won't work since this only affects the default
>printer
>> >for that.

>> I think you missed the point -- the code should *reset* the default
>printer
>> to what it was *before* the user changed it.
>> I believe that is what the original post asked about.

>> Doug.



Tue, 25 Sep 2001 03:00:00 GMT  
 Restoring the default printer
You may want to look at mskb Q173981, Print Dialog example *without*
changing the default printer.

David

    I would like to allow my users to choose which printer to print to
without changing the system default.  Alternatively, I'd like to restore the
preexisting printer to the default after I've completed printing.  I regard
changing the system default printer on the user to be poor behavior for an
application.

    I'm trying to print the contents of a RTF text box.  When the
application ends, the system printer has switched to whatever the user picks
and doesn't get restored.  Any suggestions?  This is what I'm trying:
    Private Sub mnuFilePrint_Click()
    Dim RegularPrinter As String
    Dim oPrinter As Printer
       RegularPrinter = Printer.DeviceName
       Debug.Print RegularPrinter

       CmnDlg1.Flags = cdlPDReturnDC + cdlPDNoPageNums
       If rtfMain.SelLength = 0 Then
          CmnDlg1.Flags = CmnDlg1.Flags + cdlPDAllPages
       Else
          CmnDlg1.Flags = CmnDlg1.Flags + cdlPDSelection
       End If
       CmnDlg1.ShowPrinter

       Printer.Print ""
       rtfMain.SelPrint CmnDlg1.hDC
       For Each oPrinter In Printers
          If oPrinter.DeviceName = RegularPrinter Then
             Set Printer = oPrinter
             Printer.Print ""
             Debug.Print Printer.DeviceName
             Exit For
          End If
       Next oPrinter

    End Sub



Tue, 25 Sep 2001 03:00:00 GMT  
 Restoring the default printer

Quote:

>for that.  I had a similar problem and found some code snipet which
>displayed the printer setup dialog and returned the value the values also.
>let me know if you are interested.  Also the common dialog has a property

Thanks.  I'd love it if you could post the code or direct me to it.

Unfortunetly the code below is the technique I tried and it doesn't do the
job.
Elton

Quote:
> Something like this should work:

>    Dim DevName As String
>    Dim prt As Printer

>    DevName = Printer.DeviceName

>    'add code here to change/select printer...
>    'perform print job...

>    For Each prt In Printers
>       If prt.DeviceName = DevName Then
>          Set Printer = prt
>       End If
>    Next prt



Tue, 25 Sep 2001 03:00:00 GMT  
 Restoring the default printer
This article Q173981 has nothing to do with printing without changing
the default printer.  Are you sure of the number?  This one was
related to a printing problem under NT.

George



Quote:
>You may want to look at mskb Q173981, Print Dialog example *without*
>changing the default printer.

>David

>    I would like to allow my users to choose which printer to print to
>without changing the system default.  Alternatively, I'd like to restore the
>preexisting printer to the default after I've completed printing.  I regard
>changing the system default printer on the user to be poor behavior for an
>application.

>    I'm trying to print the contents of a RTF text box.  When the
>application ends, the system printer has switched to whatever the user picks
>and doesn't get restored.  Any suggestions?  This is what I'm trying:
>    Private Sub mnuFilePrint_Click()
>    Dim RegularPrinter As String
>    Dim oPrinter As Printer
>       RegularPrinter = Printer.DeviceName
>       Debug.Print RegularPrinter

>       CmnDlg1.Flags = cdlPDReturnDC + cdlPDNoPageNums
>       If rtfMain.SelLength = 0 Then
>          CmnDlg1.Flags = CmnDlg1.Flags + cdlPDAllPages
>       Else
>          CmnDlg1.Flags = CmnDlg1.Flags + cdlPDSelection
>       End If
>       CmnDlg1.ShowPrinter

>       Printer.Print ""
>       rtfMain.SelPrint CmnDlg1.hDC
>       For Each oPrinter In Printers
>          If oPrinter.DeviceName = RegularPrinter Then
>             Set Printer = oPrinter
>             Printer.Print ""
>             Debug.Print Printer.DeviceName
>             Exit For
>          End If
>       Next oPrinter

>    End Sub



Sun, 30 Sep 2001 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Macro to change default printer and then restore original default printer settin

2. Restoring the default printer

3. Restore Printer Defaults

4. printer default to non-default printer

5. Changing Printers property reset printer to Windows default printer

6. Printer, default or not default ?

7. HOW: Restore field default?

8. restoring defaults to word document

9. Changing/restoring the Open File default directory

10. question: restoring a default

11. Restoring the default value of a form

12. restoring the default DB Grid layout after disconecting from a DB

 

 
Powered by phpBB® Forum Software