comprev_gothroughthenewsgroup@hotmail.com (Wayne Morgan) wrote in
<UQIOb.10144$N97.6294@newssvr16.news.prodigy.com >:
[color=blue]
>You don't need to GoTo ExitHere right above the ExitHere routine
>because that is where you'll go next anyway. In your error
>handler, if the error is 287 you Resume Next, but if the error is
>Case Else you give a message and drop out the bottom of the sub.
>You should put in a Resume ExitHere before the End Sub so that you
>go back up and clean up your variables. At the start of your
>ExitHere routine you may want to use On Error Resume Next, that
>way if you get to the ExitHere (due to an error that was run
>through the error routine) be fore you Open something, such as
>objMessage, you won't receive an error that it can't close the
>unopened item.
>
>ExitHere:
> On Error Resume Next
> objMsg.Close
> Set objMsg = Nothing
> objOutlook.Close
> Set objOutlook = Nothing
> ns.logoff
> Set ns = Nothing
>
> Exit Sub[/color]
I would never do that (On Error Resume Next) because my experience
is that if you don't set it back on, it sometimes remains off.
Instead, I'd test if the objects are Nothing in order to see if
they need to be cleaned up:
ExitHere:
If Not (objMsg Is Nothing) Then
objMsg.Close
Set objMsg = Nothing
End If
If Not (objOutlook Is Nothing) Then
objOutlook.Close
Set objOutlook = Nothing
End If
ns.logoff
Set ns = Nothing
Exit Sub
Or you could do something like Steve Jorgensen does and have a
subroutine that does this for you, and pass the object variable to
it. In that subroutine, you could have error handling appropriate
to the particular errors you might encounter in that particular
block, so that any errors would get handled appropriately without
getting you in a loop.
--
David W. Fenton
http://www.bway.net/~dfenton
dfenton at bway dot net
http://www.bway.net/~dfassoc