Solved

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

Posted on 2011-03-24
3
371 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
Comment Utility
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
Comment Utility
Fantastic! Thank you!
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This very simple solution applies to a narrow cross-section of the "needs to close" variety. In this case, the full message in Event Viewer was in applog, Event ID 1000: Faulting application iexplore.exe, version 8.0.6001.18702, faulting module …
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

11 Experts available now in Live!

Get 1:1 Help Now