Solved

How avoid error message when not sending email

Posted on 2014-11-06
4
152 Views
Last Modified: 2014-11-06
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?
0
Comment
Question by:SteveL13
  • 2
  • 2
4 Comments
 
LVL 25

Expert Comment

by:Shaun Kline
ID: 40426835
Was your intent to have an email sent when someone clicks the txtEmail control?
0
 

Author Comment

by:SteveL13
ID: 40426843
Yes.  But when the email window opens and if the user changes their mind and doesn't send an email the error appears.
0
 
LVL 25

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 40426902
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
 

Author Closing Comment

by:SteveL13
ID: 40426940
That did it.  Thanks.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now