Run-Time Error '2501'

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a Cmd Btn that I have setup so the user can send an E-mail. I use the
following:

Private Sub Command1362_Click()
DoCmd.SendObject acSendNoObject, , , "(e-mail address removed)", , ,
"College First Pay Inquiry for " & [name] , " A Pay Inquiry is being
requested For " & [indiv_name], , True
End Sub

It works great! BUT if the user does not send the Email from outlook he gets
the following Msg.

Run-Time Error '2501'
The SendObject Action was canceled.

I would like it to show a MSG like.

Your Email has not been sent, OK
 
KAnoe said:
I have a Cmd Btn that I have setup so the user can send an E-mail. I use the
following:

Private Sub Command1362_Click()
DoCmd.SendObject acSendNoObject, , , "(e-mail address removed)", , ,
"College First Pay Inquiry for " & [name] , " A Pay Inquiry is being
requested For " & [indiv_name], , True
End Sub

It works great! BUT if the user does not send the Email from outlook he gets
the following Msg.

Run-Time Error '2501'
The SendObject Action was canceled.

I would like it to show a MSG like.

Your Email has not been sent, OK

Private Sub Command1362_Click()
Dim lngErr As Long
On Error Resume Next
DoCmd.SendObject acSendNoObject, , , "(e-mail address removed)", ,
, "College First Pay Inquiry for " & [name] , " A Pay Inquiry is being
requested For " & [indiv_name], , True
lngErr = Err
On Error GoTo 0
Select Case lngErr
Case 0
Case 2501
MsgBox "Your email has not been sent"
Case Else
Err.Raise lngErr
End Select

End Sub
 
You need an error handler. Here's an example.

Private Sub Command1362_Click()
On Error GoTo Err_Handler
Docmd.SendObject...
Exit Sub
Err_Handler:
Select Case Err
Case 2501
MsgBox "Your email has not been sent",vbOKOnly,"Alert"
Resume Next
Case Else
MsgBox Err.Description,vbCritical,"Error #" & Err.Number
Resume Next
End Select
End Sub
 
Thank you Brian and Elwin

Brian said:
KAnoe said:
I have a Cmd Btn that I have setup so the user can send an E-mail. I use the
following:

Private Sub Command1362_Click()
DoCmd.SendObject acSendNoObject, , , "(e-mail address removed)", , ,
"College First Pay Inquiry for " & [name] , " A Pay Inquiry is being
requested For " & [indiv_name], , True
End Sub

It works great! BUT if the user does not send the Email from outlook he gets
the following Msg.

Run-Time Error '2501'
The SendObject Action was canceled.

I would like it to show a MSG like.

Your Email has not been sent, OK

Private Sub Command1362_Click()
Dim lngErr As Long
On Error Resume Next
DoCmd.SendObject acSendNoObject, , , "(e-mail address removed)", ,
, "College First Pay Inquiry for " & [name] , " A Pay Inquiry is being
requested For " & [indiv_name], , True
lngErr = Err
On Error GoTo 0
Select Case lngErr
Case 0
Case 2501
MsgBox "Your email has not been sent"
Case Else
Err.Raise lngErr
End Select

End Sub
 
Back
Top