Access VBA Best way to send an Outlook email for any version

Murray Brown
Murray Brown used Ask the Experts™
on
Hi

I am looking for Access VBA to send an Outlook email for any version of Office

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You need to use an object reference rather than referencing Outlook.

This generic code should help

Sub SendReports(DisplayMsg As Boolean, Optional AttachmentPath)
    Dim objOutlook As Object
    Dim objOutlookMsg As Object
   
    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")
   
    ' Create the message.
    Set objOutlookMsg = objOutlook.CreateItem(0)
   
    With objOutlookMsg
        '.To = strTo
        'Subject = strSubject
        '.Body = strBody
        '.Attachments.Add strAttach
        '.Save
        '.Open
    End With
    Set objOutlook = Nothing
End Sub
NoahHardware Tester and Debugger
Commented:
Hi there! :)

You might like to refer to this question over here which is similar to yours.
Reference: https://www.experts-exchange.com/questions/28429122/access-vba-create-outlook-email-send-and-save.html

Additionally, you may refer  to this link if you want to make it dynamic while showing on the database itself.
Reference: https://blueclawdatabase.com/tutorials/send-outlook-email-from-access-vba/
John TsioumprisSoftware & Systems Engineer
Commented:
Well Daniels seems to have everything covered in detail so your 1st Stop should be : https://www.devhut.net/2018/02/16/ms-access-how-to-send-an-email/
But if you want to get away from the combination of Access+Outlook (a client might not have Office) then either
CDO
or
VBSendMail
Daniel PineaultPresident / Owner CARDA Consultants Inc.
Distinguished Expert 2018

Commented:
First stop normally is DoCmd.SendObject.  If that isn't sufficient, then look into Outlook automation.  There is also CDO Mail which can be useful at times.
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Thanks a lot for all the options

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial