Hi,
I'm new to VBA coding. I'm trying to insert Error handling in my code so that if an error occurs it will retry the same line 3 times before a msgbox appears.
I'm getting a compile error label not defined at the line "On Error GoTo Err_Handler". Any help would be appreciated.
Here is my code.
Private Sub Form_Open(Cancel As Integer)
Dim x As Long
Dim lngRetries As Long
Dim lngWait As Long
Dim lngLoop As Long
On Error GoTo Err_Handler
x = 100 / 0
DoCmd.SetWarnings False
DoCmd.OpenQuery "Qry Create Shop Order", acViewNormal, acEdit
DoCmd.OpenQuery "Qry Append Shop", acViewNormal, acEdit
DoCmd.OpenQuery "Qry Append Router", acViewNormal, acEdit
DoCmd.OpenQuery "Qry_Update_Insp_Oper", acViewNormal, acEdit
DoCmd.OpenForm "Frm Drawings", acNormal
DoCmd.Close acForm, "Frm Insp Station"
End Sub
Err_Handler:
If lngRetries < 3 Then
lngWait = Int((1000000) * Rnd)
For lngLoop = 0 To lngWait
'do nothing
Next lngLoop
lngRetries = lngRetries + 1
Resume
Else
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbOKOnly Or vbInformation, "I Give Up!"
Resume ExitErrorHandler
End If
ExitErrorHandler
End Sub