calc
07-22-2009, 03:22 PM
I hope someone can help, been trying for months (on and off) to research, learn and do this myself but to no avail.
I want to email list of recipients individualised sections of report specific to them. I have found a code besides the ones at www.granite.ab.ca (http://www.granite.ab.ca/) etc and used it to develop a test db. However, I cannot get the code to work and would appreciate any and all help.
In specific I cannot understand how to go about setting up the bits in bold italics below. How do I set up the query and the report so that the code will look at and automate the attachment of sections of the report to the appropriate recipient?
I attach the db, and include below the code and instructions from the website for reference and for others to follow (there appears to be many requests for this!)
Instructions for mailing customised reports.
1. Produce your report for all members.
2. Hold the query that the report is based on (‘BaseSQL’ in the code below).
3. Open a recordset to provide the recipients.
4. Loop through this recordset, and for each recipient:
Change the query that the report is based on to include a Where clause to individualise it.
Email the individualised report to that recipient
Return the query to the original state without Where clause)
So the code will look something like this:
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim BaseSQL As String
Dim strSQL As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT ManagerID, Email FROM ManagersTable")
Set qdf = dbs.QueryDefs("YourReportQuery")
BaseSQL = qdf.SQL
With rst
Do Until .EOF
strSQL = Left(BaseSQL, Len(BaseSQL)-3) & " WHERE ManagerID =" & !ManagerID
qdf.SQL = strSQL
DoCmd.SendObject acSendReport, "YourReport", "Snapshot Format", !Email
.MoveNext
Loop
.Close
End With
qdf.SQL = BaseSQL
Set qdf = Nothing
Set rst = Nothing
Set dbs = Nothing
I want to email list of recipients individualised sections of report specific to them. I have found a code besides the ones at www.granite.ab.ca (http://www.granite.ab.ca/) etc and used it to develop a test db. However, I cannot get the code to work and would appreciate any and all help.
In specific I cannot understand how to go about setting up the bits in bold italics below. How do I set up the query and the report so that the code will look at and automate the attachment of sections of the report to the appropriate recipient?
I attach the db, and include below the code and instructions from the website for reference and for others to follow (there appears to be many requests for this!)
Instructions for mailing customised reports.
1. Produce your report for all members.
2. Hold the query that the report is based on (‘BaseSQL’ in the code below).
3. Open a recordset to provide the recipients.
4. Loop through this recordset, and for each recipient:
Change the query that the report is based on to include a Where clause to individualise it.
Email the individualised report to that recipient
Return the query to the original state without Where clause)
So the code will look something like this:
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim BaseSQL As String
Dim strSQL As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT ManagerID, Email FROM ManagersTable")
Set qdf = dbs.QueryDefs("YourReportQuery")
BaseSQL = qdf.SQL
With rst
Do Until .EOF
strSQL = Left(BaseSQL, Len(BaseSQL)-3) & " WHERE ManagerID =" & !ManagerID
qdf.SQL = strSQL
DoCmd.SendObject acSendReport, "YourReport", "Snapshot Format", !Email
.MoveNext
Loop
.Close
End With
qdf.SQL = BaseSQL
Set qdf = Nothing
Set rst = Nothing
Set dbs = Nothing