Good Morning,
I am having trouble sending an email with report attachment to all recipients in a table. The code I have written creates a report merged with the recipeint's specific information and then emails that report to that recipient. The report merge works correctly and moves through all the records, but it's sending all the emails to the first recipient. Here is what I have:
Public Function Preview()
DoCmd.SetWarnings False
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim List As Object
Dim strState As String
Dim strRpt As String
Dim strRecipientEmail As String
Dim strName As String
Dim strLetter As String
Set db = DBEngine(0)(0)
Set rst = db.OpenRecordset("tblSendTo", dbOpenDynaset)
strRpt = "rptDonorLetter"
strRecipientEmail = rst.Fields("EmailAddress"
strLetter = Forms![frmLetter]![Letter]
Do Until rst.EOF
With List
DoCmd.OpenReport "rptDonorLetter", acViewPreview
DoCmd.SendObject acReport, strRpt, "Rich Text Format(*.rtf)", _
strRecipientEmail, , , "Test Email Letter & attachment", strLetter, False, ""
DoCmd.Close acReport, "rptDonorLetter"
DoCmd.Close acForm, "frmLetter"
Forms![frmDonorEmail]![EmailAddress].SetFocus
rst.MoveNext
If rst.EOF Then
Set db = Nothing
Set rst = Nothing
Set List = Nothing
Exit Function
End If
DoCmd.GoToRecord , , acNext
End With
Loop
Set db = Nothing
Set rst = Nothing
Set List = Nothing
End Function
I'd sure appreciate it if someone could tell me how to fix this so the report goes to the right recipient, I'd be very grateful.
Thank you in advance!
Chris
I am having trouble sending an email with report attachment to all recipients in a table. The code I have written creates a report merged with the recipeint's specific information and then emails that report to that recipient. The report merge works correctly and moves through all the records, but it's sending all the emails to the first recipient. Here is what I have:
Public Function Preview()
DoCmd.SetWarnings False
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim List As Object
Dim strState As String
Dim strRpt As String
Dim strRecipientEmail As String
Dim strName As String
Dim strLetter As String
Set db = DBEngine(0)(0)
Set rst = db.OpenRecordset("tblSendTo", dbOpenDynaset)
strRpt = "rptDonorLetter"
strRecipientEmail = rst.Fields("EmailAddress"
strLetter = Forms![frmLetter]![Letter]
Do Until rst.EOF
With List
DoCmd.OpenReport "rptDonorLetter", acViewPreview
DoCmd.SendObject acReport, strRpt, "Rich Text Format(*.rtf)", _
strRecipientEmail, , , "Test Email Letter & attachment", strLetter, False, ""
DoCmd.Close acReport, "rptDonorLetter"
DoCmd.Close acForm, "frmLetter"
Forms![frmDonorEmail]![EmailAddress].SetFocus
rst.MoveNext
If rst.EOF Then
Set db = Nothing
Set rst = Nothing
Set List = Nothing
Exit Function
End If
DoCmd.GoToRecord , , acNext
End With
Loop
Set db = Nothing
Set rst = Nothing
Set List = Nothing
End Function
I'd sure appreciate it if someone could tell me how to fix this so the report goes to the right recipient, I'd be very grateful.
Thank you in advance!
Chris