Posted on 2002-04-19
I have a method that prints out a picture, and I am using the Printers collection in the code, along with the Printer object, like so:
frmMain.CommonDialog1.Flags = cdlPDReturnDC
Dim Y As Printer
For Each Y In Printers
If Y.hdc = frmMain.CommonDialog1.hdc Then
' Set printer as system default.
Set Printer = Y
' Stop looking for a printer.
The above works fine. Through this code, I aquire the printer that the user selected from the CommonDialog object. My problem is that now "Printer", which used to point to the default printer, now points to another printer, which has now become the default printer. Is there a way to set the default printer back to what it was before I changed it?
I have already tried the following:
"Dim DefaultPrinter as Printer
Set DefaultPrinter = Printer
'lines of code to do all my printing stuff
Set Printer = DefaultPrinter"
This doesn't seem to work, DefaultPrinter never receives a value. Also tried this at the very begining of the method:
Dim X As Printer
For Each X In Printers
If X.hdc = Printer.hdc Then
Set DefaultPrinter = X
This never finds a match either. I am stumped now. Any help would be appreciated.