Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, f 'file system object and rtf file to hold formatting of query
Dim outFile As String 'rtf name to hold formatting of query
Dim RTFBody As String 'query results to be read back into outlook
Dim RTFBody2 As String 'query results to be read back into outlook
Dim RTFBody3 As String 'query results to be read back into outlook
Dim strTo As String 'recipiants
Dim MyApp As New Outlook.Application
Dim MyItem As Outlook.MailItem
Dim strSubject As String 'Email subject
Dim strMsg As String 'Email greeting
Dim qryName As String 'Name of the query to be used
Dim cnt As Integer 'Number of recs in the query
Dim i As Integer 'Iteration variable
strMsg = "Below are some major accomplishments that have occurred in the Permanency department!"
strSubject = "Daily Good News from KVC Permanency"
outFile = "c:\QueryOutput.rtf"
Set fs = CreateObject("Scripting.FileSystemObject")
'***************** PERMANENCY **************************************************************
qryName = "*** PERMANENCIES ***"
If Dir(outFile) <> "" Then
Kill outFile
End If
DoCmd.RunMacro "CreateTempPermTable"
DoCmd.OutputTo acOutputQuery, qryName, acFormatHTML, outFile
cnt = DCount("*", qryName)
If cnt > 0 Then
Set f = fs.OpenTextFile(outFile, ForReading)
Do Until i = cnt + 1
RTFBody = f.ReadLine
i = i + 1
Loop
f.Close
End If
RTFBody = RTFBody & vbNewLine
i = 0
'***************** RELATIVE AND NON-RELATIVE KIN PLACEMENTS *********************************
qryName = "*** RELATIVE AND NON-RELATIVE KIN PLACEMENTS ***"
If Dir(outFile) <> "" Then
Kill outFile
End If
DoCmd.OutputTo acOutputQuery, qryName, acFormatHTML, outFile
cnt = DCount("*", qryName)
If cnt > 0 Then
Set f = fs.OpenTextFile(outFile, ForReading)
Do Until i = cnt + 1
RTFBody = f.ReadLine
i = i + 1
Loop
f.Close
End If
RTFBody = RTFBody & vbNewLine
i = 0
'***************** APA SIGNINGS ************************************************************
qryName = "*** APA SIGNINGS ***"
If Dir(outFile) <> "" Then
Kill outFile
End If
DoCmd.OutputTo acOutputQuery, qryName, acFormatHTML, outFile
cnt = DCount("*", qryName)
If cnt > 0 Then
Set f = fs.OpenTextFile(outFile, ForReading)
Do Until i = cnt + 1
RTFBody = f.ReadLine
i = i + 1
Loop
f.Close
End If
RTFBody = RTFBody & vbNewLine
'******************* SEND MAIL *************************************************************
Set MyItem = MyApp.CreateItem(olMailItem)
With MyItem
.To = "lcjohnson@kvc.org"
.Subject = "MyTestMailForGoodNews"
.BodyFormat = olFormatRichText
.HTMLBody = strMsg & RTFBody & "</BODY>" & vbNewLine & "</HTML>"
End With
MyItem.Display
'MyItem.Send