Solved

How avoid error message when not sending email

Posted on 2014-11-06
4
157 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 26

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 26

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

773 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