Error Handler Not working in Function VBA Access 2013

Viewed 167

So I have a function that allows the user to email an updated picture for an asset which works fine and good except if the user closes the email before sending. I have an error handler set up but it doesn't seem to capture the error. Here is my function code:

Function Email()
Globals.Logging "Opened Email for updating picture"
On Error GoTo ErrorHandler:
Dim strTagNumber As String
strTagNumber = Me.txtTagNumber.Value

Dim varName As Variant
Dim varCC As Variant
Dim varSubject As Variant
Dim varBody As Variant

varName = "myAnon@email.test"
varCC = ""
varSubject = "Updated Picture for Asset Number " & strTagNumber
varBody = "Sent by MS Access"

DoCmd.SendObject , , , varName, varCC, , varSubject, varBody, True, False
Globals.Logging "Sent Email"

Cleanup:
  varName = Nothing
  varCC = Nothing
  varSubject = Nothing
  varBody = Nothing
  Exit Function

ErrorHandler:
  Select Case Err.Number
    Case 2501
      MsgBox "Email message was Cancelled."
      Globals.Logging "Canceled Email"
    Case Else
      MsgBox Err.Number & ": " & Err.Description
      Globals.Logging "Email Error " & Err.Number & ": " & Err.Description
  End Select
  Resume Cleanup
End Function

Any help would be appreciated. Thank you in advance.

2 Answers
Related