I have a module that is working that creates a query and attaches the results to and email and sends it to a distribution list. What I would like to do is to put those results in the body of the email so that the results are easier to see and eventually figure out how to make it so that if there are no results no email is sent.
Code:
Function Send_Negatives()On Error Resume Next
'Set a Reference to the Microsoft Outlook ?X.X Object Library
'Get Outlook if it's running
Dim oApp As Object
Set oApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set oApp = CreateObject("Outlook.Application")
End If
Dim strReportName As String
Dim oLook As Object
Dim oMail As Object
Dim strTO As String
Dim strMessageBody As String
Dim strSubject As String
Dim HTMLBody
strReportName = "Negatives"
DoCmd.OutputTo acOutputQuery, "qry_SN_DailyNegativeQty", acFormatHTML, "R:\Sandy's playground" & "\" & strReportName & ".htm", False
Set oLook = CreateObject("Outlook.Application")
Set oMail = oLook.CreateItem(0)
'*********************** USER DEFINED SECTION ************************
strTO = "Snesmith@ctmmedia.com"
strMessageBody = "Here is the negative report"
strSubject = "Negatives"
'*********************************************************************
With oMail
.To = strTO
.Body = strMessageBody
.Subject = strSubject
.Attachments.Add "R:\Sandy's playground" & "\" & strReportName & ".htm"
'.Display
.Send
End With
Set oMail = Nothing
Set oLook = Nothing
End Function
I figured out how to send it in HTML, but I can't figure out how to put it in the body of the email.