Emailing report using a query

cktcPeterson

Member
Local time
Today, 07:16
Joined
Mar 23, 2022
Messages
74
I am trying to email "statements" (reports) to parents based on a query.

I have the query and I have the report, but right now it emails the first person in the query the selected people and the statement is all in 1.

Example: I have 3 people in my query that I want to email their individual statements.

My email button is a simple open report and email right now. I have read something about a loop???

Thanks
 
Yes, you'll need a loop to go through each record in the query. Can you post the code you're using now?
 
Code:
With Currentdb.QueryDefs("yourQueryNameHere").OpenRecordset
    Do While Not .EOF
        Docmd.SendObject acSendReport,"ReportNameHere",acformatpdf,!EmailAddress, ,,"Email subject","Email Text"
        .MoveNext
    Loop
End With
 
You also need a way to filter the report since the SendObject method doesn't offer the same options that the OpenReport method does.

As you loop through each record, you can save the CustomerID to a tempvar. Then in the report, use the TempVar as criteria.

There are several other methods if this one won't work for you because you need to run the report from multiple places and don't always want the Tempvar.
 

Users who are viewing this thread

Back
Top Bottom