How avoid error message when not sending email

SteveL13
SteveL13 used Ask the Experts™
on
I have the following code on an onclick event of an email hyperlink in a form.

Private Sub txtEmail_Click()
Dim strEmail As String

 If IsNull(Me.txtEmail) Then
 MsgBox ("There is no email address shown")
 Exit Sub
 ElseIf Me.txtEmail = " " Then
 MsgBox ("There is no email address shown")
 Exit Sub
 End If
 strEmail = Me.txtEmail
 DoCmd.SendObject , , , strEmail, , , , , True

End Sub

Open in new window


But if the user closes the email window and doesn't send an email we get an error:

"The sendobject action was cancelled"

How can we not get this error message?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Shaun KlineLead Software Engineer

Commented:
Was your intent to have an email sent when someone clicks the txtEmail control?

Author

Commented:
Yes.  But when the email window opens and if the user changes their mind and doesn't send an email the error appears.
Lead Software Engineer
Commented:
You could wrap that line of code in an On Error Resume Next statement. Something like:

strEmail = Me.txtEmail

On Error Resume Next
DoCmd.SendObject , , , strEmail, , , , , True
If Err.Number <> 0 Then
' Handle the error
End If
On Error Goto 0

Open in new window

Author

Commented:
That did it.  Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial