Emailin (outlook) query results

claris

New member
Local time
Today, 15:56
Joined
Nov 7, 2008
Messages
7
Hi All

I am running a module out of Access, and want to include the results of two queries in the body of the email, as well as attaching an attachment.


Currently I have -


If audit = "Y" Then
DoCmd.Close acQuery, "AUDITSUMFINAL"
DoCmd.Close acQuery, "AUDITSUMFINALCUST"
Set App = CreateObject("Outlook.Application")
Set Park = App.CreateItem(0)
Edate2 = DLookup("DAY_DATE", "ENDDATE")
With Park
.Subject = "Park Garages Weekly WE " & Edate2
.To = customeramiladdress@domain.com
.CC = "account managers"
.Attachments.Add "blah blah blah" & Edate & ".csv"
*******************************************************
.display
End With
End If


**** indicates where I think there should be a line of code that inputs the results of the audit queries, but I have no idea what it could be.

Anyone on the know?
Happy Friday

Claris =]
 
.body is the one for the main body of the email.

could you open a recordset of the query results, then loop through the recordset adding it to a string? What format are you looking for in the query results?


Code:
dim rs as DAO.Recordset
dim strBody as String
 
set rs = currentdb.openrecordset("qryYourQuery")
 
rs.movefirst
 
do while not rs.EOF
   strBody = strBody & rs.field1 & rs.field2 etc etc & vbCrLf
   rs.movenext
loop
 
rs.close
set rs = Nothing
 
 
'stick this in your email making section:
.body = strBody
 
sorry that shoud be rs!field1 etc (not rs.field1 etc)
 
Hello

Yeh I sorted this one about ten minutes after I posted, must have been Friday brain malfunction, but thanks for your time and help. I did it in a slightly different way, Dim'ed a load of fields, with dlookups for the values, and added them in, in a particularly long string of .body = "Period Ending " & EDate2 & vbCrLf & vbCrLf & "Fuel" & vbCrLf & "Fuel Deals: " & FuelCost.

It's a never ending statement of spaces and fields, but it's worked for me.

Thanks again

Happy Monday

Claris:D
 

Users who are viewing this thread

Back
Top Bottom