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.

Thanks!
Senniger1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

omgangIT ManagerCommented:
expression.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc, Subject, MessageText, EditMessage, TemplateFile)

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

OM Gang
0
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
0
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_cmdTestEmail_Click:
      Exit Sub
Err_cmdTestEmail_Click:
      Resume Exit_cmdTestEmail_Click
End Sub

Any idea why this is happening?

Thanks!
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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
0
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")
    OutApp.Session.Logon
       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!
0
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
0
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_SendObjectTest:
    Exit Function
   
Err_SendObjectTest:
    MsgBox Err.Number & ", " & Err.Description, , "Error in function SendObjectTest"
    Resume Exit_SendObjectTest
   
End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
0
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.
0
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.

Thanks,
OM Gang
0
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.