Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report table or query in Email body on sendobject

Status
Not open for further replies.

Raynepau

Technical User
Dec 30, 2010
33
GB
Can anyone help with the following

I am trying to find some suitable code to place text from a report, query or table in the body of an email where each new record is a new line in the email

I am not sure if this is possible

Thanks
 
To send the email in code, I use the CDO object, which you can google more about, or check out this web page:


Somewhere in the process of writing to your CDO email object, you run into "Textbody", and it is at that point you want to write your record values out to string variables, and then you use the string variables to concantenate your text body like so:

Set rsSomeData as New ADODB.recordset

rsSomeData.open, "sometable", currentproject.connection, etc

with rsSomeData
do

CustName=!CustName
CustAddr=!CustAddr
CustCity=!CustCity
CustSales=!Custsales

cdoObject.Textbody=cdoObject.Textbody&" "&CustAddr&" "&CustCity&" "&str$(CustSales)&vbcrlf

.movenext

loop until .eof

End with

The vbcrlf constant pushes the cursor to a newline in the textbody, so you want to make sure you add it whereever you want a record to end. If you need it in nice neat table format, you will have to pad your data with spaces or you will need to go to much more complex code that writes the table out to the clipboard and then to the .Textbody
 
Excellent and many thanks - I'll give this a try and let you know how it goes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top