Error on sending email

G

Guest

Hello,

I have some code attached to a cmdButton so that a user may send an email
from the form with the information from the current record. The code and
button works perfectly! However, if the user clicks the button an the email
appears and the users chooses NOT to send it after all, they get an error.

Here is the error they get:

Run Time Error '2501'

The SendObject action was cancelled.

Here is the code:

Private Sub Command39_Click()
Dim SendTo As String, MySubject As String, MyMessage As String
SendTo = ""
MySubject = "Issue"
MyMessage = Me.LoanNumber & vbCr & Me.CustomerFirst & " " & Me.CustomerLast
& vbCr & Me.ErrorCode & _
vbCr & Me.Comments
DoCmd.SendObject acSendNoObject, , , SendTo, , , MySubject, MyMessage, True

End Sub

Could someone please tell me how I can stop getting this error if they
choose not to send the email after clicking the button? Also, could you
please tell me where in this code it would go?

Thank you in advance!!
 
N

Nick 'The database Guy'

Hi Doug,

Firstly I have got to say that I am unaware of any code at the moment
that will send an email from access that does not first ask the user to
confirm that they want to send. So that leaves us with the jbo of
tidying up the error. I suggest something like:

Private Sub Command39_Click()
On Error GoTo err_
Dim SendTo As String, MySubject As String, MyMessage As String

<<Code Body>>

Exit Sub

err_:
Select Case Err.Number
Case 2501
Msgbox "The mail has not been sent"
Case Else
MsgBox "An error occured. Please check for obvious reasons
and/or technical support" & vbNewLine & "Error " & Err.Number & " : " &
Err.description, vbExclamation
End Sub
 
G

Guest

Hi Nick,

When I placed the code in, it turned red on this part:

and/or technical support" & vbNewLine & "Error " & Err.Number & " : " &

I really do not need to have a message pop up, I just don't want the error
to pop up. If there is a way to prevent it that would be great but if not, I
will instruct everyone not to click the button unless they are sure they want
to send an email.

Thanks Nick!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

How to CC in an email 9
BCC Email 3
Email problem 5
Email Issue 1
SendObject Email 2
Sending Email from Form 5
Emailing with field name in body of email 7
Email fro FORM 4

Top