How avoid error message when not sending email

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?
SteveL13Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Shaun KlineConnect With a Mentor Lead Software EngineerCommented:
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

0
 
Shaun KlineLead Software EngineerCommented:
Was your intent to have an email sent when someone clicks the txtEmail control?
0
 
SteveL13Author Commented:
Yes.  But when the email window opens and if the user changes their mind and doesn't send an email the error appears.
0
 
SteveL13Author Commented:
That did it.  Thanks.
0
All Courses

From novice to tech pro — start learning today.