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
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 "Just cannot find a way to do it"
On error GOTO HandleError
ErrorCount = 0
Resume Next
[/tt]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.