Inserting query results into MESSAGE body of email

A

Angie

Hello, I know how to use SendObject to attach a file to my email, but is
there a way to display the results within the body of an email (not an
attachment). Thanks so much!!
 
S

Smartin

Angie said:
Hello, I know how to use SendObject to attach a file to my email, but is
there a way to display the results within the body of an email (not an
attachment). Thanks so much!!

The way I've done this is to build up a string while looping through a
recordset based on the query. Then just assign the text to the body
property of the message.
 
A

Angie

I think that is my issue. Could you post a sample of code for me? How do I
dim recordset and how do I refer to each record as it loops through?
 
S

Smartin

Angie said:
I think that is my issue. Could you post a sample of code for me? How do I
dim recordset and how do I refer to each record as it loops through?

Here's the general idea:

Function EmailBody() As String
Dim RS As DAO.Recordset
Dim tmpEM As String
Dim sSQL As String
sSQL = "SELECT blah blah blah;"
Set RS = DBEngine(0)(0).OpenRecordset(sSQL)
RS.MoveFirst
Do While Not RS.EOF
' Here we start looping through the records
' Reference the fields on each record with Fields(n) below.
' Create a loop across the fields if you have a lot of them (^:
tmpEM = tmpEM & Nz(RS.Fields(0).Value, "") & ";"
' Debug.Print tmpEM ' uncomment this line and step through code to see
what's going on here
RS.MoveNext
Loop
EmailBody = tmpEM
Set RS = Nothing
End Function

Hope this helps!
 
Top