Create a new module, name it "modSendAttachments"
insert the following code
Public Sub SendMessage(DisplayMsg As Boolean, strObjectName As String)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim arrAttach(1)
Dim i As Integer
arrAttach(0) = ExportObject(strObjectName, acFormatRTF)
arrAttach(1) = ExportObject(strObjectName, "Snapshot Format")
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Your Email Recipient")
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Your CC")
objOutlookRecip.Type = olCC
' Add the BCC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Your BCC")
objOutlookRecip.Type = olBCC
' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "This is the body of the message." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
For i = 0 To 1
Set objOutlookAttach = .Attachments.Add(arrAttach(i))
Next
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
End Sub
Public Function ExportObject(strObjectName As String, varFormat As Variant)
Dim strPathFile As String
Select Case varFormat
Case acFormatRTF
strPathFile = "C:\Temp\" & strObjectName & ".rtf"
DoCmd.OutputTo acOutputReport, strObjectName, varFormat, strPathFile, False
Case "Snapshot Format"
strPathFile = "C:\Temp\" & strObjectName & ".snp"
DoCmd.OutputTo acOutputReport, strObjectName, varFormat, strPathFile, False
End Select
ExportObject = strPathFile
End Function
You need to change the recipient to, cc, and bcc, subject, and body text info in the SendMessage procedure.
Then to actually send the message, use
Call SendMessage(True, "YourReportName")
If you don't want to view the message before sending, change the first parameter to false.
Let me know how it works for you.
One more thing! While viewing the code, you need to add reference to Microsoft Outlook Object library. Go to tools, references, then check it in the list.