Stop error from occurring after aborting e-mail message

eduardo

Registered User.
Local time
Today, 01:31
Joined
Jul 5, 2012
Messages
67
Hi there, I have a simple code for an access form button to send a email message.

It looks like this:

DoCmd.SendObject , , , [emailaddress], , , [CustomerId], "Dear " & [CustomerName] & "We inform you that (...)"

When I click the button an email message window pops up, and if I do SEND it, everything ends well.

The problem:

If choose NOT to send it, and I close the email message window, an error pops up causing my database to close (I use access runtime).


Do you think I can add anything to my vba so this error doesnt occur?

Thanks!
 
Last edited:
Hmm, what is the error message? Can't trap it if we don't know what it is...
 
Hmm, what is the error message? Can't trap it if we don't know what it is...

"Run-time error 2501
SendObject action was cancelled"

It's because I didnt click on 'send', is there a code that I can add so that error doesnt show?
 
If you want the error to just not show without notifying the User under the Private Sub YourCommandButton_Click() put

Code:
On Error Resume Next

Never tried that but it might work.
 
If you want the error to just not show without notifying the User under the Private Sub YourCommandButton_Click() put

Code:
On Error Resume Next

Never tried that but it might work.

Excellent, it did work. Thanks GinaWhipp
 
Me again.

I noticed that although "On Error Resume Next" appeared to work well, after a few tests of cancelling the email, MS ACCESS crashes. (images attached).

I tried other forms of "On Error", such as "On Error GoTo 0", or "On Error GoTo ErrorHandler" but it keeps on crashing.

I'm using MS Access 2013 Plus Professional 64bits for Windows 8.

Any ideas on why this is happening?
 

Attachments

  • Capture.PNG
    Capture.PNG
    21.8 KB · Views: 121
  • vba.PNG
    vba.PNG
    7.1 KB · Views: 110
Last edited:
Why do you have Exit Sub twice? You could remove the first one.

As for the crashing, I'm wondering if calling Outlook multiple times and then canceling is not giving the line to *catch up*. Hmm, but I just tested and no crashing here, even when *rushing* the clicking the button.

Hmm, another thought, try...
Code:
DoCmd.SendObject , , , Me.emailaddress, , , Me.CustomerId, "Dear " & Me.CustomerName & "We inform you that (...)"
 
I know, it occurs randomly.

I now tried removing one of those Exit Sub, and the crash occurred but much later, like after about 10 times of repeating the process of clicking on the button and closing the email message.

I guess it wont be a big deal under a normal use.

Again thanks for your patience.
 
Hmm, not happy about the crashing but I would think if someone cancels 10 eMails in a row they are just playing... :D So, I will have to agree, under normal use this should not be a problem BUT you should probably still work on the Design Master to track down the crashing.

Lightbulb, try changing
Exit Sub to DoCmd.CancelEvent
 
Tried with DoCmd.CancelEvent and it keeps on randomly crashing.

I'm starting to think that the responsible for this is my notebook or something external to Access.

Gonna try this out in another PC tomorrow.
 
It shouldn't matter but it will be interesting to see the results as it didn't crash for me and I tested on a PC.
 
It shouldn't matter but it will be interesting to see the results as it didn't crash for me and I tested on a PC.

Tested under Windows 7 / Office 2010, the error is successfully handled, and access won't freeze. #Thankfully. :D
 
this sort of thing is fuller error handling

error 2501 is a general "some action failed" code - but it depends exactly why it failed.
maybe emailaddress or customerid is null, etc. not sure if that would cause a problem

Code:
 on error goto fail
 DoCmd.SendObject , , , [emailaddress], , , [CustomerId],
 exit sub
  
 fail:
 if err<>2501 then msgbox "Error: " & err & "  Desc: " & err.description
 

Users who are viewing this thread

Back
Top Bottom