Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Error RETRY

Status
Not open for further replies.

pascalxricher

Programmer
Oct 22, 2001
14
0
0
CA
Hi!

Is it possible to do a Retry on the line that caused the error in an error handling ?
 
Just use the GoTo statement. You must be sure to handle the potential endless loop. Here is some rough code to show you how to use the GoTo statement. I am not going to get into the whole "use of goto" issue.
Code:
Sub SomeSub()
    Dim i As Integer

    On Error Goto ErrHndlr
    'some code here

    On Error Goto Retry
Retry:
    Err.Clear
    i = i + 1
    If i = 10 GoTo CutItOut
    'Code You Want To Retry

CutItOut:
    Err.Clear

    On Error Goto ErrHndlr
    'Remainder of Code
End Sub
Hope this helps...
 
Yes it is

Sub MyError()
.
.
.
On Error Goto ErrHndl

i = 100/y ' Error if y = 0
.
.
.

ErrHndl:

Select Case Err.Number
Case 11 'Division by 0 Error
msgbox " Cannot Divide By Zero",vbInformation,"Error"
Exit Sub
Case Else
Resume
End Select
End Sub

If the error is a divide by zero error the sub will exit other wise it will return to the line that created the error. You need to make sure you handle the error when you do this otherwise you could end up with a infinite loop and a program lock up

Anything is possible, the problem is I only have one lifetime.
 
You can even change the on error state.
[tt]
HandleError:
Dim ErrorCount
ErrorCount = ErrorCount + 1
If 3 < ErrorCount then
ON error GOTO FailError
endif

'... Adjust to attempt error resolution ...

Resume

FailError:
MsgBox &quot;Just cannot find a way to do it&quot;
On error GOTO HandleError
ErrorCount = 0
Resume Next
[/tt]

Wil Mead
wmead@optonline.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top