Vba On Error Goto Retry

[Solved] Vba On Error Goto Retry | Vb - Code Explorer | yomemimo.com
Question : vba on error goto retry

Answered by : braxton-bell

'Counter for the errors ErrorCount = 0 GoTo CheckConnection 'This statement is pointless if the label is directly after it
CheckConnection: 'Try to execute the query ' This says to go to BadConnection if an error occurs after it, ' not if an error occurred previously On Error GoTo BadConnection db.Execute sqlq ' Start allowing errors to crash Excel again On Error GoTo 0 'Query worked - continue processing '.... '... Exit Sub
'Error handling code
BadConnection: ' Start allowing errors to crash Excel again On Error GoTo 0 If ErrorCount = 5 Then 'If the query failed 5x, just give up and show the error message MsgBox "Giving up" Exit Sub End If 'Add +1 to the counter ErrorCount = ErrorCount + 1 'Allow the application to wait for 5 minutes Application.Wait (Now + TimeValue("0:05:00")) 'Try the query again by Resuming at CheckConnection Resume CheckConnection

Source : https://stackoverflow.com/questions/45813664/vba-if-error-try-again | Last Update : Sat, 18 Jun 22

Answers related to vba on error goto retry

Code Explorer Popular Question For Vb