using the results of a query in the body of an E-mail

F

FedWerkker

I've been attaching Excel or Word to an e-mail for years now, but now I need
to do something different. I need to take a query and fill in the Body of an
E-mail. I think it has to do with a Recordset, Loop and building a string,
but I don't quite have the thought process down, Any HELP or ideas?
thanks!
 
J

Jack Leach

The result of a query is nothing but raw data. How would you like to format
it? It can go into an excel sheet, and then into an email, or into a report,
which can then be put in an email.

I suppose if you really wanted to put just the query result into an email
you could export it as a delimited text, but in essance, a query has no
format at all... you need some means of displaying the data that the query
collects.

hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
J

Jack Leach

The result of a query is nothing but raw data. How would you like to format
it? It can go into an excel sheet, and then into an email, or into a report,
which can then be put in an email.

I suppose if you really wanted to put just the query result into an email
you could export it as a delimited text, but in essance, a query has no
format at all... you need some means of displaying the data that the query
collects.

hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
D

Dirk Goldgar

FedWerkker said:
I've been attaching Excel or Word to an e-mail for years now, but now I
need
to do something different. I need to take a query and fill in the Body of
an
E-mail. I think it has to do with a Recordset, Loop and building a
string,
but I don't quite have the thought process down, Any HELP or ideas?
thanks!


In principle, it would be something like this:

'------ start of example code ------

Dim rs As DAO.Recordset
Dim strBody As String

' Set prefatory part of message body.
strBody = "Hi! Here's some nice juicy data for you:" & vbCrLf

Set rs = CurrentDb.OpenRecordset("YourQuery")
With rs
Do Until .EOF

' Append data from current record to the message body.
strBody = strBody & vbCrLf & _
!SomeField & " " & !SomeOtherField

' Proceed to next record.
.MoveNext
Loop
.Close
End With

' Append any closing text.
strBody = strBody & vbCrLf & vbCrLf & _
"Yours truly," & _
"The Fount of All Knowledge"

' Send the message.
DoCmd.SendObject _
To:="(e-mail address removed)", _
Subject:="Data For You", _
MessageText:=strBody

'------ end of example code ------
 
D

Dirk Goldgar

FedWerkker said:
I've been attaching Excel or Word to an e-mail for years now, but now I
need
to do something different. I need to take a query and fill in the Body of
an
E-mail. I think it has to do with a Recordset, Loop and building a
string,
but I don't quite have the thought process down, Any HELP or ideas?
thanks!


In principle, it would be something like this:

'------ start of example code ------

Dim rs As DAO.Recordset
Dim strBody As String

' Set prefatory part of message body.
strBody = "Hi! Here's some nice juicy data for you:" & vbCrLf

Set rs = CurrentDb.OpenRecordset("YourQuery")
With rs
Do Until .EOF

' Append data from current record to the message body.
strBody = strBody & vbCrLf & _
!SomeField & " " & !SomeOtherField

' Proceed to next record.
.MoveNext
Loop
.Close
End With

' Append any closing text.
strBody = strBody & vbCrLf & vbCrLf & _
"Yours truly," & _
"The Fount of All Knowledge"

' Send the message.
DoCmd.SendObject _
To:="(e-mail address removed)", _
Subject:="Data For You", _
MessageText:=strBody

'------ end of example code ------
 
F

FedWerkker

Thank you, I've copied the code. I will have to internalize what it's doing.
This is very usable.
 
F

FedWerkker

Thank you, I've copied the code. I will have to internalize what it's doing.
This is very usable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top