Unable to trap error 2501 properly

  • Thread starter Thread starter Kurt Schupley
  • Start date Start date
K

Kurt Schupley

I have the following sub routine:

Public Sub EmailResults()
Dim stDocName As String
On Error GoTo MailError

DoCmd.SetWarnings False
stDocName = "EmailSearchResults"
DoCmd.SendObject acSendReport, stDocName,
acFormatRTF, , , , "Account Balances Due", _
"Please find account balances attached.", False


Exit_EmailResults:
On Error Resume Next
Exit Sub

Exit_MailError:
Exit Sub

MailError:
If Err.Number = 2501 Then
MsgBox "Email was cancelled"
Else
MsgBox Err.Description
End If

Resume Exit_EmailResults
End Sub

WHAT THIS SUB DOES: Opens up Outlook, attaches the
specified file.

Everything works well, except if the user decides not to
send the email and clicks on the X to close Outlook XP
SP2. Error 2501 does occur, which I've trapped, however
an additional error window appears stating "The
SendObject Action was canceled" and then the system is
stuck - no way out but to end the Access process.
Interestingly enough, if I have the database window open
behind the form that calls this subroutine, everything
works great! However, I do not want my users to see the
database window, so on startup, it is disabled, thus my
catch 22.

Any help from you Access wizards out there would be much
appreciated!
 
MailError:
If Err.Number = 2501 Then
MsgBox "Email was cancelled"
Else
MsgBox Err.Description
End If

In your error handler, add the error number to your description to find out
the number of the other error and see if you can trap it as well.

MsgBox Err.Description & vbCrLf & "Error Number: " & Err.Number
 
Back
Top