With the help provided by Remou in thread181-1091473 I was able to automate the sending of email notifications of MDO "Mandatory Day Off" and PTO "Paid Time Off" time off being taken by a specified group of empolyees. This all works well except there are some days that no one is scheduled off and then the recipients would receive an email with no data for the body, in other words, blank. Can someone help me rewrite this code so the email will only be sent if there is data for the report. The record source for the report is a query called qryMDO. As always your expertise and help is much appreciated. Following is the code I have so far.
Private Sub Command24_Click()
On Error GoTo Err_Command24_Click
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, f
Dim RTFBody, strTo
Dim MyApp As New Outlook.Application
Dim MyItem As Outlook.MailItem
DoCmd.OutputTo acOutputReport, "rptMDO", acFormatHTML, "rptMDO.htm"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("rptMDO.htm", ForReading)
RTFBody = f.ReadAll
f.Close
Set MyItem = MyApp.CreateItem(olMailItem)
With MyItem
.To = Me.txtSendTo
.Subject = "MDO/PTO notification"
.HTMLBody = RTFBody
End With
MyItem.Send
DoCmd.Close
Exit_Command24_Click:
Exit Sub
Err_Command24_Click:
MsgBox Err.Description
Resume Exit_Command24_Click
End Sub
Private Sub Command24_Click()
On Error GoTo Err_Command24_Click
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, f
Dim RTFBody, strTo
Dim MyApp As New Outlook.Application
Dim MyItem As Outlook.MailItem
DoCmd.OutputTo acOutputReport, "rptMDO", acFormatHTML, "rptMDO.htm"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("rptMDO.htm", ForReading)
RTFBody = f.ReadAll
f.Close
Set MyItem = MyApp.CreateItem(olMailItem)
With MyItem
.To = Me.txtSendTo
.Subject = "MDO/PTO notification"
.HTMLBody = RTFBody
End With
MyItem.Send
DoCmd.Close
Exit_Command24_Click:
Exit Sub
Err_Command24_Click:
MsgBox Err.Description
Resume Exit_Command24_Click
End Sub