Individual Report to each Staff member

F

Fev

Hi
I would really appreciate some help with the following code. I have a
form to complete the subject and email message - the data source is
tblStaff which contains each e-mail address. My report is based on a
query that references the Staff ID number in the form for each
individual report. My problem is the line:

DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, myPath &
"\" & myFile, True

It loops through the staff table, creating the same report 66 times.
I need to somehow output 1 report per loop, using the Staff ID and
then attach that report to the e-mail and send.

For nRecNo = 1 To myTotRec
fileName = [FirstName] & Left([LastName], 1)
Set myItem = myObject.CreateItem(0)
With myItem
.Subject = strSubject
.To = strUsers
If Len(Trim(strBody)) > 0 Then
.Body = strBody
End If
Application.Echo False
myFile = Me.cboCycle.Column(1) & "-" & fileName
stDocName = "rptIndivPeerReport"
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, myPath &
"\" & myFile, True
DoCmd.Close acReport, "rptIndivPeerReport"
myStr = myPath & "\" & myFile
Set myAttachments = myItem.Attachments
myAttachments.Add myStr, _
olByValue, 1, "Peer Review Names for"
.Send
SendMail = "Message placed in outbox with " _
& intAttachments & " file attachment(s)."
End With

rs.MoveNext
Me.Requery

Next nRecNo

I would appreciate some help with the code - I have studied the link:
http://www.granite.ab.ca/access/email/recordsetloop.htm
but cannot see where I am going wrong.
Thanks
Heather
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top