0
votes

Apologies in advance - This could be a long one - All Code added in the bottom.

I'm working on a database for tracking support tickets. I've been trying to clear up the errors that have been popping up with the tracker - so I started working an rebuild - Cleaning code - Changing field names etc - It was an entirely new database that no one had access to. But for some reason, my error code doesn't seem to catch any more. So let me explain everything.

The front end is opened and on open, loads the login form - This utilizes DLOOKUP to check and match passwords - This is fine After logging in, the ticket entry form loads (Frm_ticket_Entry) this has multiple fields for data and 2 buttons. (I'll only list a few as none are actually mandatory)

Field names:

    Ticket_Number - (fairly self explanatory)
    Agent         - (Agent working ticket)
    Return_Team   - (if ticket was returned)

Buttons:

    New Record - (Adds a new record - Guess you can tell that)
    Save Record - (saves record after data changes)

When using Err.raise("error number") - My catcher works as expected

When I turn err.raise off (comment out) and run everything - I sometimes hit "Run-Time Errors" (Such as locked for editing) on my previous DB version - This was caught by my error catcher - and produced the custom output - Now, it does not seem to want to catch the run-time errors - Why not, what is going wrong!? (apologies for the extensive read - I struggle to describe things accurately, but briefly. - Further info available if required / Requested)

Code for "New Record":

Private Sub btn_NewRecord_Click()
    DoCmd.GoToRecord , , acNewRec 'Add a new record
    Me.Ticket_Number = "#" ' Change ticket number textbox to "#"
    Me.Kickback_Reason = "Pass to next level support" ' - Set Default entry for kick back reason
    Me.Agent = User() ' Set "Agent" field to the currently logged in user
    Me.Returning_Team = "CSC Service Desk" ' Set default for "Returning Team"
    DoCmd.RunCommand acCmdSaveRecord 'Save the record into the table
    DoCmd.GoToRecord acDataTable = tbl_Tickets, , acLast ' return to the last saved record

On Error GoTo Error_Handle    
'    Err.Raise 3314, "btn_New_Record_Click()", "Errored" ' Force error for debug purposes
'    Err.Raise 2105, "btn_New_Record_Click()", "Errored"
'    Err.Raise 21345, , "Unknown Error Occured"
Exit Sub

Error_Handle:

Call ErrorLogger(Err.Number, Err.Description, Err.Source)    
  Err.Clear
  MsgBox "Error Trapping complete"    
  Resume Next    
  End Sub

And code for ErrorLogger:

    Function ErrorLogger(ErrNum As Integer, ErrDesc, ErrSrc As String)

Select Case ErrNum

Case 3314 ' You must enter a value in the 'tblKickbacks.Ticket Number' field.
MsgBox "It seems some required fields may not have been completed! " _
& "Please ensure you have filled in 'Ticket Number' / 'Agent' /     'Returning Team' and/or 'Kickback Reason'"

If IsNull(Me.Ticket_Number) Then
Me.Ticket_Number.SetFocus
End If

If (MsgBox("Error " & ErrNum & " occured." & vbNewLine _
& "Details : " & ErrDesc & vbNewLine _
& "Error occured in : " & ErrSrc & vbNewLine _
& "Would you like to send an email error report?" _
, 4 Or 16, "ERROR DETECTED")) = vbYes _
Then
    GoTo DevEmail
Else
    GoTo Err_Exit
End If

Case 2105 ' You can't go to the specified record.

MsgBox "Error Caught - 2105"

Case 3218 ' Error Description: Could not update; currently locked.

'   Need to find and add code here for forcibly unlocking any and ALL locked records

Case Else
MsgBox "Error : " & ErrNum & " -- " & ErrDesc & " " _
& "Not recognised - Sending error email"
GoTo DevEmail

End Select

DevEmail:

Dim oAPP As Outlook.Application
Dim oMail As Outlook.MailItem

' Create the Outlook session.
Set oAPP = New Outlook.Application

' Create the message.
Set oMail = oAPP.CreateItem(olMailItem)

With oMail
    ' Add the To recipient(s) to the message.
    .To = "[email protected]"
    .Subject = "Tracker V2 Error"
    .Body = "Error message as Follows:" & vbNewLine _
                    & "Error Number: " & ErrNum & vbNewLine _
                    & "Error Description: " & ErrDesc & vbNewLine _
                    & "Error Source: " & ErrSrc
    .Send
End With
MsgBox "Email has been sent"

Err_Exit:        
End Function
2

2 Answers

2
votes

Move On Error GoTo Error_Handle at first line.

Private Sub btn_NewRecord_Click()
    On Error GoTo Error_Handle    

    ...

End Sub
0
votes

There's nothing between on error goto errhandle and exit sub you need that line above the code that adds the new record