Outlook Automation

Emailing From Outlook

Emailing From Outlook | Microsoft Access Sample Code

Function for Emailing From Outlook

Sending Emails from Microsoft Access Using Outlook Automation

A frequent requirement for Microsoft Access users is the ability to send emails directly from within an Access application. While Access provides a built-in SendObject function that can handle basic emailing needs, it may not suffice for more complex scenarios, such as attaching multiple files or customizing email properties. For these advanced needs, Outlook Automation offers a powerful solution by allowing you to interact directly with Microsoft Outlook through VBA (Visual Basic for Applications).

Outlook Automation unlocks advanced features that are not available with the native Access functions. It enables you to attach files, customize recipients, preview emails before sending, and even handle rich text or HTML email bodies. Below, you’ll find a VBA function, doEmailOutlook, that demonstrates how to send an email using Outlook as the mail client.

VBA Function for Sending Emails with Outlook Automation

The following VBA code provides a comprehensive way to send emails from Access using Outlook:

Public Sub doEmailOutlook(sTo As String, sSubject As String, sBody As String, sFile As String, Optional bFileAttach As Boolean = False, Optional bPreview As Boolean = False)
On Error GoTo doEmailOutlookErr

    Dim strEmail As String
    Dim strMsg As String
    Dim oLook As Object
    Dim oMail As Object

    Set oLook = CreateObject("Outlook.Application")
    Set oMail = oLook.createitem(0)
    With oMail
        .ReplyRecipients.Add "YourEmail@YourDomain.com"
        .to = sTo
        '.body = sBody
        .htmlbody = sBody
        .Subject = sSubject
        If sFile <> "" Then
            .Attachments.Add (sFile)
        End If
        If bFileAttach = True Then
            .Attachments.Add (CurrentProject.path & "\YourFile.pdf")
        End If
        If bPreview = True Then
            .display
        Else
            .Send
        End If
    End With

    If bPreview = False Then
        Set oMail = Nothing
        Set oLook = Nothing
    End If
    Exit Sub

doEmailOutlookErrExit:
    Exit Sub

doEmailOutlookErr:
    MsgBox Err.Description, vbOKOnly, Err.Source & ":" & Err.Number
    Resume doEmailOutlookErrExit
End Sub

Key Features of the doEmailOutlook Function

  • Supports sending HTML-formatted emails for better presentation and customization.
  • Allows file attachments, including dynamically generated files such as reports.
  • Includes an option to preview the email before sending (bPreview parameter).
  • Integrates seamlessly with Microsoft Outlook to manage email sending and delivery.

Additional Resources: Microsoft Access Email Database Template

If you are looking for a pre-built solution to manage email functionality within your Access database, consider the Microsoft Access Email template database. This template includes examples and workflows for automating email tasks, such as sending reports and notifications. It can be customized to meet your specific requirements. If the template doesn’t meet your needs fully, contact us for a quote to develop the custom features you need.

Download a Demonstration

Are you having problems getting the code to work for you? If you answered yes, try the demo version to see if the demo works for you!

Download a demo version for free to try out. The demo version is in Access 2007 which will work on either Access 2007, 2010, 2013, 2016, 2019 or Office 365. If you need a previous version of Access to tryout, please Contact Us. Please note that the demo version of the software is fully functional but doesn't allow you to see the code implementation - the full version allows you to design the code implementation and tweak it for your needs.

Access 2007 Download

Access 2010/2013/2016/2019/Office 365 Download

Access 2010 Download - 64 Bit

Access 2013/2016/2019/Office 365 Download - 64 Bit

Access 2003 Download

Live Demonstration: To experience a more interactive and personalized demonstration of this WSI template, we invite you to contact WSI and schedule a live demonstration with one of our team members. This opportunity allows you to engage directly with us, either as an alternative to or in conjunction with downloading and exploring the demo version of the template at your leisure. Please note that downloading Microsoft Office files, including Microsoft Access database files, might trigger a security warning on your computer. To avoid this and get a comprehensive overview, you have the option of viewing the template through a virtual meeting on Teams or Zoom with a WSI representative.
Once you purchase the database template, you will receive the full version of the database in a standard Access Database file. The purchased database will have full access to the database window, all design objects, the visual basic project code, and you will be able to modify or add to the design in any way you wish (this does not apply to the run-time/compiled versions). If you lack the time to integrate this database into your system, please Contact Us and we will be glad to help with your integration process. If you like the basics of what you see in the database, but need enhancements to make the system functional for your business, please Contact Us and we will develop a quote for you to implement the additional features and enhancements that you require.


Sample Screens



Purchase Price

$24.99 - this allows you to use this database template however you wish within your organization.
Access Template Database

$49.99 for unlimited developer use - this allows you to use this database template however you wish for any applications you develop and distribute.
Access Template Database

Once your purchase is complete - you will receive an email within 12 Hours (shorter during standard business hours) with a link to download the full version of the database. Please be sure and check your junk mail folder as this often ends up there.

If you need any help implementing this function or modifications made for your needs, to get a free quote for your Microsoft Access Development needs.  WSI will determine your needs based on written requirements that you provide. Please ask your WSI representative to send you an example of what constitutes sufficient written requirements. If you need assistance preparing the necessary requirements, WSI offers a fee based service to assist you. Please ask your WSI representative for details or you can review our process mapping service.

WSI offers optional paid support and customization programming services. WSI templates are priced based on the purchaser self-supporting the database. WSI assumes purchasers, who do not wish to pay WSI for support, have a level of knowledge of Microsoft Access and Microsoft SQL server to enable them to self-perform installation, customization and use of the template. WSI does offer paid support in these areas by the hour. Please Contact Us for the current hourly fee.

To learn more about the WSI quoting process.

Microsoft Access Email Common Questions

We have a number of automated emails we wish to send out each night or on a scheduled basis - Can you make it happen?

Absolutely! We have developed a number of nightly/scheduled programs that send out emails per the specifications you provide. Contact us today for a free estimate to begin to see how quickly WSI can help you.

Want quick Answers?

Email Now

Call Now

About Us

WSI is a small business and a leading provider of custom access programming and database solutions for government entities, Fortune 1000 companies, and emerging businesses. We are your custom access development experts.