Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Button Suddenly Stops Working

Status
Not open for further replies.

rosieb

IS-IT--Management
Sep 12, 2002
4,279
0
0
GB
I have a button on a form which opens an email using DoCmd.SendObject, it was working fine then suddenly started to produce an error message "Microsoft Office Access can't send this email message"

I've tried creating a new database from scratch with a second form which has a button that opens a blank email, rebuilding my original button step by step and testing the blank email at each point. However both stop working at apparently random points.

I'm using Access 2003.

Any suggestions would be greatly appreciated.



Rosie
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong." Richard Feynman
 
Are you trying to attach a file that's not allowed to send through email?

Also, have you looked into using the Microsoft Outlook Data object reference? With that, you can take full control of Outlook for sending your email.

I just set up something over the past couple of days, and part of it is sending out an email a couple of times, attaching an Excel file..

Here's a snippet of what I'm using:
Code:
' One Outlook reference [URL unfurl="true"]http://www.rondebruin.nl/sendmail.htm[/URL]
' Modified from: [URL unfurl="true"]http://bytes.com/topic/visual-basic/answers/447877-using-vba-email-w-attachments[/URL] with minor changes
    Dim olApp As New Outlook.Application
    Dim olNewMail As Outlook.MailItem
    Set olNewMail = olApp.CreateItem(olMailItem)
    With olNewMail
        .Display
        fnPause (1)
        .To = "Mickey Mouse"
        .CC = "Donald Duck"
        SendKeys ("{TAB}")
        SendKeys ("^k") 'Forces Outlook to Check Names - To field
        SendKeys ("{TAB}")
        SendKeys ("^k") 'Forces Outlook to Check Names - CC field
        .Subject = "I'm Sending you an Email!"
        .Body = "Howdy, Goofy sends his regards."
        .Attachments.Add "C:\MyFile.xlsx", olByValue
        .Send
    End With
    Set olNewMail = Nothing
    Set olApp = Nothing
 
Hi, I don't think it's the attachment, it's just an Access report and it worked for the first couple of times. It won't even let me open an email with no attachments.

I'll look into the using the Microsoft Outlook Data object reference.

Thanks

Rosie
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong." Richard Feynman
 
I also recommend using the Outlook Object Model to generate your e-mail... it gives you full control over the email and will likely eliminate your error. The one caveat is that it is signifcanly 'different' than other object models.

To kjv1611:

I am not a big fan of 'Sendkeys.' It is a somewhat shaky way to do what you want.

Try this:
Code:
Dim olThisRecipient as Outlook.Recipient

olThisRecipient = olNewMail.Recipients.Add ("Mickey Mouse")
olThisRecipient.Type = olTo
If olRecipient.Resolve = False Then [i]WhatToDoIfItFails[/i]

olThisRecipient = olNewMail.Recipients.Add ("Donald Duck")
olThisRecipient.Type = olCC
If olRecipient.Resolve = False Then [i]WhatToDoIfItFails[/i]
...

If you don't want to check each individual address, you can use
Code:
olNewMail.Recipients.ResolveAll
to validate your addresses all at once. Simpler and more reliable.
 
rosieb said:
Hi, I don't think it's the attachment, it's just an Access report and it worked for the first couple of times. It won't even let me open an email with no attachments.
Actually, in that case, thinking about it... I think that might have to do with the security limitations added by MS around the time they released '03 or '07. They put some limits in place on certain email functions, so it was not as easy for SPAMMERS to use Access to build spambots.

Gammachaser,

Thanks for the alternative for the namechecking. I honestly wasn't too concerned about using any checking on the names, but thought I'd just give the SendKeys bit a try in my scenario. I should have included a mention that yes, SendKeys can be quite messy at times. Whenever there's another way, the other way should be used for sure.


"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
Oh, I'll try to test Gammachaser's method on the name checking later this week, hopefully. I plan on revisiting the project where I'm using that anyway, as I've got some other loose ends to iron out.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top