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.
VIDEO
Download a Demonstration
Full Version and Live Demonstration Options
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.
After purchase
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 run-time or 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 the additional features you require.
Sample Screens
Main Menu Form
Main Menu - Modern Look (Access 2010/2013)
Previous
Next
Purchase Price
$24.99 - this allows you to use this database template however you wish within your organization.
$49.99 for unlimited developer use - this allows you to use this database template however you wish for any applications you develop and distribute.
After Your Purchase
Delivery timing
Once your purchase is complete, you will receive an email within 12 hours, and usually sooner during standard business hours, with a link to download the full version of the database. Please check your junk mail folder if you do not see the message.
Implementation help
If you need help implementing this function or need modifications for your requirements, request 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 for an example of sufficient written requirements.
Support and customization
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 the Microsoft Access and SQL Server knowledge needed to install, customize, and use the template. Paid support is available by the hour; please contact us for the current hourly fee.
Planning your changes
If you need assistance preparing requirements, WSI offers fee-based services to help document what needs to be done. You can also review our process mapping service or learn more about the WSI quoting process .