Jezebel
Thu Aug 26 20:29:29 CDT 2004
You could also be selective about which particular errors to ignore by
checking the value of Err.Number
"Jay Freedman" <jay.freedman@verizon.net> wrote in message
news:f52ti0tm7uaac1q9c5up6256tkppq18ur3@4ax.com...
> You can remove some of the risk by deciding in advance how many loops
> you're willing to allow. Something like this:
>
> Const MAXLOOPS = 1000
> Dim nLoops As Long
> nLoops = 0
> On error resume next
> Do
> SomeFunction
> nLoops = nLoops + 1
> Loop Until (Err.Number = 0) Or (nLoops > MAXLOOPS)
> If nLoops > MAXLOOPS Then
> MsgBox "SomeFunction timed out"
> End If
> On error goto 0
>
> --
> Regards,
> Jay Freedman
http://aspnet2.com/mvp.ashx?JayFreedman
> Microsoft Word MVP FAQ:
http://word.mvps.org
>
> "Jezebel" <dwarves@heaven.com.kr> wrote:
>
> >It's perfectly reasonable to ignore errors that are not harmful -- in
fact
> >there are some things that you really can't do any other way. However,
you
> >can't make the Loop instruction itself conditional. Here is cleaner code
for
> >what you are trying to do --
> >
> >On error resume next
> >Do
> > SomeFunction
> >Loop until Err.Number = 0
> >On error goto 0
> >
> >But, this is VERY risky coding unless you can be confident that
SomeFunction
> >returns only non-critical errors, and that it will succeed on subsequent
> >attempts. If the error is unrecoverable your code will loop for ever.
> >
> >
> >
> >
> >"Ed" <Ed_Millis@NOSPAM.yahoo.com> wrote in message
> >news:uH4yMt7iEHA.1344@TK2MSFTNGP11.phx.gbl...
> >> I had an idea, and thought I would post it here to see if it survived
> >> scrutiny. A line in my macro errored because another process wasn't
> >> completely done. Is it possible and would it be okay to use On Error
> >Resume
> >> Next and the error code with an IF to loop back through the missed
> >> instruction until it completes?
> >>
> >> I'm thinking something like:
> >>
> >> Do
> >> On Error Resume Next
> >> ' Do This
> >> If Err.Number <> 0 Then
> >> Loop
> >> Else Exit Do
> >> End If
> >> On Error GoTo 0
> >>
> >> Ed
> >>
> >>
> >
>