Link to home
Start Free TrialLog in
Avatar of GoCellular_ca
GoCellular_ca

asked on

Problem sending email from form in Access 2007 vb (DoCmd.SendObject)

Hi,
We've upgraded from Access 2003 to 2007 and I'm having problems with a vb function sending emails from an Access form. Everything works fine - it opens the email box in Outlook, when I click on "send email" in Outlook it sends it immediately, BUT it doesn't close the email window. All commands in the window are disabled, if I wait about 20 seconds it closes itself, or I can click on the close button.
This never used to happen in 2003, when I sent the email the email window would close.
What am I doing wrong?
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Any other code running other than the SendObject? Can you post the full SendObject call?


good afternoon!

can u post ur code of sending email.


game-master

try this approach!


sub Send
    Dim objMsg As Object
    Dim objConfi As Object
    Dim strBody As String
   
    Set objMsg = CreateObject("CDO.Message")
    Set objConfi = CreateObject("CDO.Configuration")
   
    With objMsg
        Set .configuration = objConfi
        .to = <receiver>
        .from = <sender>
        .Subject = "Test"
        .textbody = "This is a test message only."
        .send
    End With
   
    MsgBox "OK"
end sub
Avatar of GoCellular_ca
GoCellular_ca

ASKER

game-master:
 Thanks for the tip, but with your code I'm getting the error "Runtime Error -2147220960 (80040220) The SendUsing configuration is invalid"

LSMConsulting:
No, there's no code running apart from this:
DoCmd.SendObject acSendNoObject, , acFormatRTF, strRecipient, , , strRegarding, strBodyText, True

strRecipient, strRegarding and strBodyText are all simple text strings - I've tried writing recipient etc. directly in the DoCmd.SendObject line but it makes no difference.
I"m beginning to think that this might be a problem with Outlook 2007 instead of a local problem in Access?
SendObject does nothing more than open the message in Outlook (or whatever your default email client happens to be). Once this happens, processing is passed to Outlook. If you have code running after this line (add a MsgBox to verify this), that code will fire immediately - which indicates that Access has passed the object to Outlook and returned to it's own code duties.

As to why this worked in 03 - I've never had it work this way. If I use SendObject with the Show argument set to True, then Outlook would open my message and wait for me to do something with it, but it wouldn't close. As I've said many times before 2007 is much more picky about code and such, and many things that worked in earlier versions have been fixed (for right or wrong) in 2007. Access should have never had any control over the email client simply by calling SendObject ... it would be different if you were actually automating your client, but SendObject does nothing more than add an email to the Outbox of the email client - nothing more. The Show argument (i.e. the one you set True to view the message) simply showed the message and allowed you to interact with it.
ASKER CERTIFIED SOLUTION
Avatar of game-master
game-master
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@game-master: works perfectly, thank-you very much for your help!


good morning!

Im glad i could help..


game-master