PC Review


Reply
Thread Tools Rate Thread

docmd send object sending all records to each person

 
 
Marcie
Guest
Posts: n/a
 
      2nd Mar 2009
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

 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      2nd Mar 2009
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]
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Docmd Send Object - multiple CC fields from a form Paul Worsnop Microsoft Access Form Coding 3 14th Jul 2009 04:09 PM
DoCmd.Send Object ---PDF File ? Bgreer5050 Microsoft Access Reports 1 20th Jan 2007 04:45 AM
Mail merge-send data of 3 person to 1 person in 1 letter =?Utf-8?B?TlAwNw==?= Microsoft Access External Data 0 24th Aug 2006 03:34 PM
Want one mailing label per person, but query can have multiple records per person Bob Richardson Microsoft Access 5 22nd Dec 2005 08:39 PM
Send Object - sending queries to specific Recipient =?Utf-8?B?U2VuZE9iamVjdCAtIE1hY3Jvcw==?= Microsoft Access Macros 0 2nd Sep 2005 09:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:53 PM.