You can use the reports source query. Here is the code I am currently using, adapt it to suit your needs:-
Code:
Dim MyDb As DAO.Database
Dim rsEmail As DAO.Recordset
Dim sToName As String
Dim sSubject As String
Dim sMessageBody As String
Set MyDb = CurrentDb()
Set rsEmail = MyDb.OpenRecordset("6g Daily Email Query", dbOpenSnapshot)
With rsEmail
.MoveFirst
Do Until rsEmail.EOF
If IsNull(.Fields(0)) = False Then
sToName = .Fields(0)
sSubject = "Todays Testing for " & .Fields(1)
sMessageBody = "Below is a listing of testing work for you Today. If you need a detailed listing of tests, please contact the Testing Team who will provide this. " & vbCrLf & _
"Number of Tests Due to Complete Today: " & rs.Fields(2) & vbCrLf & _
"Number of Tests Due to Start Today: " & rs.Fields(3) & vbCrLf & _
"Number of Tests Past Planned Completion Date: " & rs.Fields(4) & vbCrLf & _
"Number of Tests Past Planned Start Date: " & rs.Fields(5) & vbCrLf & _
"Number of Tests Due to Start Tomorrow Prep Not Complete: " & rs.Fields(6)
DoCmd.SendObject acSendNoObject, , , _
sToName, , , sSubject, sMessageBody, False, False
End If
.MoveNext
Loop
End With
Set MyDb = Nothing
Set rsEmail = Nothing
ErrorHandlerExit:
Exit Sub
ErrorHandler:
If Err = 3021 Then
MsgBox "There are no records to send"
End If