Results 1 to 3 of 3
  1. #1
    jtmott is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2013
    Posts
    17

    On error Goto Problem

    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

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,523
    you cant have 2 END SUBs, use EXIT SUB

    DoCmd.Close acForm, "Frm Insp Station"
    Exit Sub

    Err_Handler:
    ...
    ...
    end sub

  3. #3
    jtmott is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2013
    Posts
    17
    That fixed it! Thanks for the help

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Goto Record Problem
    By The Professor in forum Forms
    Replies: 6
    Last Post: 02-15-2013, 04:39 PM
  2. Error Handling Question - On Error Goto
    By redbull in forum Programming
    Replies: 7
    Last Post: 12-06-2012, 07:54 AM
  3. Goto Record
    By jgalloway in forum Forms
    Replies: 8
    Last Post: 09-25-2011, 08:03 AM
  4. Replies: 7
    Last Post: 12-13-2010, 03:12 PM
  5. On Error GoTo does not resume?
    By easbrandel in forum Programming
    Replies: 5
    Last Post: 04-15-2010, 04:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums