On Mon, 2 Mar 2009 08:23:01 -0800, Marcie <(E-Mail Removed)>
wrote:
>I have the following code to send an email to each recipient in the
>payrolldetail table. I only want it to send there information but it is
>sending everyones. Can anyone see what I am doing wrong?
>
>Dim rs As Recordset
>Set rs = CurrentDb.OpenRecordset("PayrollDetail")
>
>rs.MoveFirst
>While Not rs.EOF
>strEmail = rs!Email
>
>strid = rs!ID
>
>DoCmd.OpenReport "ContractFacntp", acViewPreview, , strid
>
>DoCmd.SendObject acSendReport, "ContractFACNTP", "PDFFormat(*.pdf)",
>strEmail, , , "Contract"
>DoCmd.Close acReport, "ContractFACNTP"
>
>rs.MoveNext
>Wend
>rs.Close
>Set rs = Nothing
The problem is that the Report that it's sending is evidently based on the
entire table. You're passing strid in the WhereCondition argument; that's
defined in the help as
Optional Variant. A string expression that's a valid SQL WHERE clause without
the word WHERE
What you're passing is just a number - 3456 or whatever that record's ID is.
Access can't recognize that as a valid SQL WHERE clause; in fact I'm surprised
it isn't giving an error message!
Try
DoCmd.OpenReport "ContractFacntp", acViewPreview, , "ID = " & strid
to limit the report to that individual ID.
--
John W. Vinson [MVP]
|