Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2011-03-24
3
373 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 - Microsoft MVP, Access and Data Platform) 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
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…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

860 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