Solved

Is There a Way to Force the E-mail in a DoCmd.SendObject Command?

Posted on 2011-03-24
3
372 Views
Last Modified: 2012-06-21
I am using the following code...
DoCmd.SendObject acSendNoObject, , , semail, , , "Level 2 Product CAR Root Cause Report", sBody
...to send an e-mail when a command button is ciicked.

However, if the user closes the e-mail without clicking Send, it crashes and I get the following error saying the Object was cancelled.

Is there a way to force the e-mil through without requiring the user to click Send?

...or....is there a way to keep the code from crashing like that if they do cancel the object?

Thanks

 Error When e-mail cancelled
0
Comment
Question by:Rex85
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
ID: 35209748
Try this:

On Error Resume Next
DoCmd.SendObject acSendNoObject, , , semail, , , "Level 2 Product CAR Root Cause Report", sBody

Select Case Err.Number
    Case 0
      '  no error occurred
    Case 2501
        Err.Clear ' ignore - user cancelled
    Case Else
        'MsgBox " Unexpected error  " & Err.Number & "  " Err.Description
End Select

 ' continue on ...

mx
0
 

Author Closing Comment

by:Rex85
ID: 35209803
Fantastic! Thank you!
0
 
LVL 75
ID: 35209836
You are welcome.  Note at a similar thing can happen when opening reports say from a 'Report Setup' Form ... and the report has no data, and user closes the report.

DoCmd.OpenReport "YourCoolReport", acPreview

Select Case Err.Number
    Case 0
      '  no error occurred
    Case 2501
        Err.Clear ' ignore - user cancelled
    Case Else
        'MsgBox " Unexpected error  " & Err.Number & "  " Err.Description
End Select
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

777 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