June,
Its just my editing mistakes when I take out the signature block, I think. Otherwise I do not get any compilation errors. I am wanting to create 2 seperate emails. With the below code, it creates the first email, then changes it to the second email. I need it to create the second email in a different message.
Code:
PPrivate Sub Send_Daily_Click()
On Error GoTo ErrorMsgs
Dim rs As DAO.Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookAttach As Outlook.Attachment
Dim strBody, strAddresses, strSubject, strMsg As String
Dim CRNUM As Variant
Set rs = CurrentDb.OpenRecordset("SELECT Status,CR_Numbers,[Change Requested]FROM Daily_Actions_Email ORDER BY Status,CR_Number ASC")
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
CRNUM = DLookup("[CR_Numbers]", "[Daily_Actions_Email]", "CR_Numbers")
If IsNull(CRNUM) Then
With objOutlookMsg
.Subject = "There were no actioned CR's - " & Format(Date + 1, "dd mmm yyyy")
.Body = "There were no actioned Change Requests today." & vbCrLf & vbCrLf & "V/R" & vbCrLf & vbCrLf & "Name" & vbCrLf & vbCrLf & "Command" & vbCrLf & "Division" & vbCrLf & "Address" & vbCrLf & "Zip" & vbCrLf & "Phone" & vbCrLf & "Email"
.To = "TEWG CCB Results"
.Display
DoCmd.Close acReport, "Daily Actions"
Exit Sub
End With
Else
End If
rs.MoveFirst
While Not rs.EOF
strMsg = strMsg & rs!Status & vbCrLf & Chr(9) & "CR " & rs!CR_Numbers & " - " & rs![Change Requested] & vbCrLf
rs.MoveNext
Wend
rs.Close
With objOutlookMsg
.Subject = "Today's AORB/ERB/CCB outcome - " & Format(Date, "dd mmm yyyy")
.Body = "Today's AORB/ERB/CCB outcome." & vbCrLf & vbCrLf & strMsg & vbCrLf & vbCrLf & "V/R" & vbCrLf & vbCrLf & "Name" & vbCrLf & vbCrLf & "Command" & vbCrLf & "Division" & vbCrLf & " Address" & vbCrLf & "Zip" & vbCrLf & "Phone" & vbCrLf & "Email"
DoCmd.OutputTo 3, "Daily Actions", acFormatPDF, "C:\Temp\Daily Actions - " & Format(Date, "dd mmm yyyy") & ".pdf", , 0
.Attachments.Add ("C:\Temp\Daily Actions - " & Format(Date, "dd mmm yyyy") & ".pdf")
.To = "TEWG CCB Results"
.Display
DoCmd.Close acReport, "Daily Actions"
Kill "C:\Temp\Daily Actions - " & Format(Date, "dd mmm yyyy") & ".pdf"
End With
With objOutlookMsg
.Subject = "Today's AORB/ERB/CCB outcome - " & Format(Date, "dd mmm yyyy")
.Body = "Today's AORB/ERB/CCB outcome." & vbCrLf & vbCrLf & strMsg & _
vbCrLf & vbCrLf & "V/R" & vbCrLf & vbCrLf & "Name" & vbCrLf & vbCrLf & "Command" & vbCrLf & "Division" & vbCrLf & "Address" & vbCrLf & "Zip" & vbCrLf & "Phone" & vbCrLf & "Email"
DoCmd.OutputTo 3, "Weekly SITREP V", acFormatXLS, "C:\Temp\Summation - " & Format(Date, "dd mmm yyyy") & ".xls", , 0
DoCmd.Close acForm, "Bi-Summation"
.Attachments.Add ("C:\Temp\Summation - " & Format(Date, "dd mmm yyyy") & ".xls")
.To = "HB Rollup"
.Display
Kill "C:\Temp\Summation - " & Format(Date, "dd mmm yyyy") & ".xls"
DoCmd.Close acReport, "Weekly SITREP V"
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookAttach = Nothing
Exit Sub
ErrorMsgs:
If Err.Number = "287" Then
MsgBox "You clicked No to the Outlook security warning. " & "Rerun the procedure and click Yes to access e-mail " & "addresses to send your message."
Else
MsgBox Err.Number & " " & Err.Description
End If
End Sub