Ensure that the entire procedure is carries out.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am running into a problem. Sometimes the following procedure will run and
stop half way through (MS Access 2002 w/ the latest SP's just locks up and
stops responding). When it does that it leaves the strSlipPrinter as the
deafault printer and does not change back to the strCurrentPtr (the current
default printer). Is there a way to ensure that the current default printer
is changed back once the procedure completes or fails? There are other
programs that use the default printer for reports. When it stays on the
label printer (strSlipPrinter), the reports print out on labels. This is no
good!

-------start of code----------
Dim strCurrentPtr As String
Dim strSlipPrinter As String

strSlipPrinter = DLookup("[Printer]", "[DefaultLabelPrinter]", "[ID]
= 1")
strCurrentPtr = GetDefaultPrinter
SetDefaultPrinter strSlipPrinter
DoCmd.OpenReport "PackageSlip", acViewNormal
DoCmd.OpenReport "MailboxSlip", acViewNormal
SetDefaultPrinter strCurrentPtr
------------------end of code-----------------
 
James

I noticed no error handling routine in your code.

If you want to ensure that the procedure ALWAYS leaves setting the printer
back to the "current" one, have you tried adding that command in as part of
a combined error-handler/exit process?

You could consider adding something like:

On Error GoTo ErrorHandler

... (your code here)

ExitHere:
SetDefaultPrinter strCurrentPtr
Exit Sub

ErrorHandler:
Msgbox Error.Number & " - " & Error.Description
Resume ExitHere

End Sub

(your actual syntax may vary)
 
I actually posted only a portion of the code. I do have error handling, but
not " SetDefaultPrinter strCurrentPtr" under Exit. I will try that and
see if that will work. Thank you for your help!

Jeff Boyce said:
James

I noticed no error handling routine in your code.

If you want to ensure that the procedure ALWAYS leaves setting the printer
back to the "current" one, have you tried adding that command in as part of
a combined error-handler/exit process?

You could consider adding something like:

On Error GoTo ErrorHandler

... (your code here)

ExitHere:
SetDefaultPrinter strCurrentPtr
Exit Sub

ErrorHandler:
Msgbox Error.Number & " - " & Error.Description
Resume ExitHere

End Sub

(your actual syntax may vary)

--
Good luck

Jeff Boyce
<Access MVP>

James said:
I am running into a problem. Sometimes the following procedure will run and
stop half way through (MS Access 2002 w/ the latest SP's just locks up and
stops responding). When it does that it leaves the strSlipPrinter as the
deafault printer and does not change back to the strCurrentPtr (the current
default printer). Is there a way to ensure that the current default printer
is changed back once the procedure completes or fails? There are other
programs that use the default printer for reports. When it stays on the
label printer (strSlipPrinter), the reports print out on labels. This is no
good!

-------start of code----------
Dim strCurrentPtr As String
Dim strSlipPrinter As String

strSlipPrinter = DLookup("[Printer]", "[DefaultLabelPrinter]", "[ID]
= 1")
strCurrentPtr = GetDefaultPrinter
SetDefaultPrinter strSlipPrinter
DoCmd.OpenReport "PackageSlip", acViewNormal
DoCmd.OpenReport "MailboxSlip", acViewNormal
SetDefaultPrinter strCurrentPtr
------------------end of code-----------------
 
Back
Top