Good morning! I'm at the point of doing the same thing over and over, expecting to get a different result. I need a fresh pair of eyes please. We email an invoice reminder each month. The original statement works perfectly. But (even though I've copied the report and most of the function) the reminder report being emailed includes everyone's statement. Here's the code:
Code:
Private Sub Command104_Click()Dim oApp As New Outlook.Application
Dim oEmail As Outlook.MailItem
Dim filename As String, todayDate As String
Dim rst As DAO.Recordset
Dim LastName As Variant
Dim strBody As String, lngCount As Long, lngRSCount As Long
Dim StrTo As String
Me.AssessmentType1 = "roads"
DoCmd.OpenQuery "DeleteACCTTABLETEMP"
DoCmd.OpenQuery "AppendAsmtsandAccountsCurrentRoadstotesttable"
DoCmd.OpenQuery "ACCOUNTSBALFWDFINALTOTAL"
Set rst = CurrentDb.OpenRecordset("SELECT * FROM [EmailRoadsGroupAsmtHeader]ORDER BY [lastname];", dbOpenSnapshot)
Do While Not rst.EOF
strRptFilter = "[memberid_PK] = " & rst![MemberID_PK]
Debug.Print rst![MemberID_PK]
DoCmd.OpenReport "EmailRoadsAssessmentReminder", acViewPreview
DoCmd.OutputTo acOutputReport, "EmailRoadsAssessmentReminder", acFormatPDF, "C:\HAH Database FE\Emailtests" & "\" & rst![MemberID_PK] & "REMINDERroads.pdf"
DoCmd.Close acReport, "EmailRoadsAssessmentReminder"
DoEvents
Set oEmail = oApp.CreateItem(olMailItem)
With oEmail
StrTo = rst!InvoiceEmail
filename = "C:\HAH Database FE\Emailtests" & "\" & rst![MemberID_PK] & "REMINDERroads.pdf"
Debug.Print filename
Debug.Print rst!InvoiceEmail
.TO = StrTo
Debug.Print StrTo
Debug.Print filename
.Subject = "Roads Statement Attached"
.Body = "Thank you"
.Attachments.Add filename
.Display
rst.MoveNext
'
'
End With
Loop
MsgBox "Email successfully sent!", vbInformation, "EMAIL STATUS"
End Sub
The data is correct, but again, each members' statement includes all members' statements. I hope this is clearer than mud. TIA!