VBA SendObject from Access and Outlook 2010, but Display Message before Sending

We just upgraded from Office 2003 to Office 2010.  So I now have Access 2010 and Outlook 2010.

I used the sendobject method to send an email from Access to Outlook.   Here is my code.

   DoCmd.SendObject , , acFormatTXT, From, CCTo, BCCTo, stSubject, stText, False

I'd like to be able to view the email before sending it in case I want to type extra text.  Research shows "Display" is what I'm wanting to do, but I cannot figure out how to apply it to my code.

Any help would be appreciated.

Who is Participating?
omgangIT ManagerCommented:
I tested this evening.  Windows 7 64-bit, Office 2010 (Access 2010, Outlook 2010).  It functions as expected with Outlook open or closed.
OM Gang

This is my test procedure

Public Function SendObjectTest()
On Error GoTo Err_SendObjectTest

    Dim CCTo As String, BCCTo As String, stSubject As String, stText As String
    CCTo = "omgang@ee.com"
    BCCTo = "Senniger1@ee.com"
    stSubject = "This is a test message 2"
    stText = "Testing"

    'DoCmd.SendObject(, , , CCTo, BCCTo, stSubject, StText, True)
    DoCmd.SendObject , , , CCTo, BCCTo, , stSubject, stText, True

    Exit Function
    MsgBox Err.Number & ", " & Err.Description, , "Error in function SendObjectTest"
    Resume Exit_SendObjectTest
End Function
omgangIT ManagerCommented:
expression.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc, Subject, MessageText, EditMessage, TemplateFile)

DoCmd.SendObject(, , , CCTo, BCCTo, stSubject, StText, True)

OM Gang
omgangIT ManagerCommented:
Take a look at VBA Help for the SendObject method.  It provides the details for all the parameters.  In your case I left out the parameter OutputFormat because you're not sending any type of object - that's why I removed the acFormatTXT.
Hope this helps.
OM Gang
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Senniger1Author Commented:
Thank you for your help.  I had done all the above previously before posting and couldn't get anything to work.

Here's my simplified code.  What I discovered is if Outlook 2010 is closed, the code works fine.  If I have Outlook open, then the code doesn't work.  

Private Sub cmdTestEmail_Click()
On Error GoTo Err_cmdTestEmail_Click
    'Write the e-mail content for sending to assignee
        DoCmd.SendObject , , , "JDoe@senniger.com", , , "Subject", "Body of Email", True
      Exit Sub
      Resume Exit_cmdTestEmail_Click
End Sub

Any idea why this is happening?

omgangIT ManagerCommented:
It works as expected for me in Access 2007/Outlook 2007.  I can test this evening in Access 2010/Outlook 2010.
OM Gang
Senniger1Author Commented:
Any luck with testing in Access 2010/Outlook 2010?

I ended up finding another solution since I wasn't sending any type of object (code below).  This seems to work well for this situation, but it would be nice to know how to use the SendObject in future projects.
    Set OutApp = CreateObject("Outlook.Application")
       StrBody = "<html><head></head><body>"
       StrBody = StrBody & "***** Body of Email" *****" _
       StrBody = StrBody & "</body></html>"
    Set OutMail = OutApp.CreateItem(0)
    OutMail.To = From
    OutMail.CC = CCTo
    OutMail.BCC = BCCTo
    OutMail.Subject = stSubject
    OutMail.HTMLBody = StrBody
    OutMail.Display 'Send | Display
    Set OutMail = Nothing

Thanks so much for your help!
omgangIT ManagerCommented:
The advantage to using SendObject in your situation is the code is more portable, e.g. it will/should work with the default mail client on the machine, Outlook Express, Windows Live Mail, etc.  The Outlook automation code depends upon Outlook being installed on the machine and won't work if it is not.  Still, a good solution if it works for you.  I forgot to check out SendObject in Office 2010 at home.  I'm sending myself a message as a reminder so I'll do it this evening.

OM Gang
Senniger1Author Commented:
Sorry for the delay.  Let me test your proceedure on Windows XP which is what we're using and I'll get back to you.
Senniger1Author Commented:
When I tested your code I got a Run-time error '2293'.

Upon further investigation, I believe my issue is the fact that when I right click on a file on my desktop and select Send To, Mail Recipient, it doesn't work.  I suspect this may be my issue.  I'll work to repair this issue.

Thank you so much for you help and I did use the information you provided.
omgangIT ManagerCommented:
Make sure Outlook (or Windows Live Mail, Outlook Express, etc.) is configured as the default mail program on the computer/for the user profile.  In Windows 7 there is a Default Programs applet in Control Panel.  I'll check on Windows XP here in a bit.

OM Gang
omgangIT ManagerCommented:
In Windows XP the applet is located in the Add or Remove Programs dialogue.  It's titled set Program Access and Defaults.  You may also have a link to it in your start menu.  Make sure you have a default mail program specified.

OM Gang
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.