Logo

My Access Tips for Custom Microsoft Access

Application Development

by Matthew V Carmichael


Need Help?

My Tips


Links

Resources
Quick Tip Details
Question:
How can I automatically email a report via Outlook using the SnapShot format?
Answer:
The following code illustrates how to output and attach a report as a snapshot viewer file to an Outlook Email.
This code can be used to replace the SendObject command (if you are using Outlook as your mail client).
Please make sure to add the Microsoft Outlook Object Library to your References.
Code:
Function EmailSnpFile()

    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    Dim strPath As String
    
    'Output Report as Snapshot file
    strPath = CurrentProject.Path
    DoCmd.OutputTo acOutputReport, "Your Report Name", acFormatSNP, strPath & "\Report.snp"

    'Create e-mail item
    Set objMail = olApp.CreateItem(olMailItem)

    With objMail
       .To = "email@mydomain.com"
       .Subject = "Your Subject"
       .BodyFormat = olFormatHTML
       .HTMLBody = "" & "Your Email Body" & ""
       .Attachments.Add strPath & "\Report.snp"
       .Display
    End With

End Function