I am trying to send multiple emails with attached files at once. The code should take each record and populate to the report then attached that report to email and send it. The email address has in each record in the table. My table has around 1000 records, so i need to email around 1000 records with attached file. Please help. Thank you.
Dim db As DAO.Database Dim rs As DAO.Recordset
Dim strEmail As String Dim strID As String Dim strLetterName As String
Dim stDocName As String Dim stPath As String Dim stFile As String
stDocName = "rpt_Letter" stFile = Dir(strID & ".snp") Set db = CurrentDb() Set rs = CurrentDb.OpenRecordset("select id, LetterName, EmailTo from tblLetter")
With rs If (Not .BOF) And (Not .EOF) Then ..MoveFirst strEmail = .Fields("EmailTo") strID = .Fields("id") strLetterName = .Fields("LetterName") ..MoveNext End If If (Not .BOF) And (Not .EOF) Then Do Until .EOF strEmail = .Fields("EmailTo") strID = Reports![rpt_Letter].Report![txtid] ' how to populate data to the attached report? strLetterName = Reports![rpt_Letter].Report![txtName] ' how to populate data to the attached report? ..MoveNext Loop End If ..Close End With
DoCmd.SendObject acReport, stDocName, acFormatSNP, strEmail, , , "test", "Testing...", , stFile
End Sub
|
|