In a previous post, the code shown below was given to open MS Outlook and pre-fill the "To:" field with Email Addresses listed in a query.
I would now like to know how to modify this code so the Email (Outlook) would include an attachment. The attachment would either be an Access report (example: rpt_MyReport) and display as a WORD document; or the attachment would be a list of data from a query (example: qry_MyData) and display as an Excel document. To clarify, I want these to be "attachments."
Please note if there are any property/setting changes within Access that will be required to allow permissions for the code to run.
Private Sub Command3_Click()
Function fncEmail() As Boolean
Dim rst As ADODB.Recordset
Dim strTo As String
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Set rst = New ADODB.Recordset
rst.Open "SELECT Email FROM qry_Email", CurrentProject.Connection
'/now create the outlook message
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
Do Until rst.EOF
strTo = strTo & rst("Email") & ";"
Set objOutlookRecip = .Recipients.Add(strTo)
objOutlookRecip.Type = olTo
.Subject = "Email Subject"
'/.Body = "Body Here"
.Display '/Note: to automatically send the email without previewing, change this to .Send
Set objOutlook = Nothing
Set objOutlookMsg = Nothing
Set objOutlookRecip = Nothing
Set rst = Nothing