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

Re: Use IF to Loop or not? AND IF w/ error codes? by Jezebel

Jezebel
Thu Aug 26 18:21:44 CDT 2004

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
>
>



Re: Use IF to Loop or not? AND IF w/ error codes? by Jay

Jay
Thu Aug 26 20:09:18 CDT 2004

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
>>
>>
>


Re: Use IF to Loop or not? AND IF w/ error codes? by Jezebel

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
> >>
> >>
> >
>



Re: Use IF to Loop or not? AND IF w/ error codes? by Ed

Ed
Mon Aug 30 08:57:14 CDT 2004

Please excuse the long delay - the weekend jumped up and bit me!

"Malcolm Smith" <malcolm.smith@DragAndDrop.com> wrote in message
news:memo.20040827072306.18568B@mksmith.aits-uk.net...
> Ed
>
> I think that the solution here is the wrong way of going about things.
> Exactly what is being done and what is the process for which you are
> waiting?

I'm saving a document twice, once using Save and immediately again using
SaveAs. If the process isn't complete when it drops to the next
instruction, it errors. Maybe because I've got Background Saves turned on?

Ed