I am trying to loop through a recordset to send multiple emails. Most of my code is from Microsoft and I have adapted it to my needs as far as attachments.
I need to send emails to multiple people each having a different attachment.
The code runs without error BUT it will only send the first record.
I have looked at this code trying to find the error of my ways for 3 days and trying different things, yet I can’t change the outcome. Can someone please offer some insight as to what I’m doing wrong? Please?
Thanks in advance.
Public Sub Send_Second_Attempt_Fax() Dim MyDB As Database Dim MyRS As Recordset Dim str_Report_Name As String Dim str_MyFilename As String Dim str_myAttach As String Dim str_MyPath As String Dim str_ToFaxName As String Dim str_FaxNum As String Dim objOutlook As Outlook.Application Dim objOutlookMsg As Outlook.MailItem Dim objOutlookRecip As Outlook.Recipient Dim objOutlookAttach As Outlook.Attachment Dim TheAddress As String Set MyDB = CurrentDb Set MyRS = MyDB.OpenRecordset(“qry_MyQRYName”) MyRS.MoveFirst ‘ Create the Outlook session. Set objOutlook = CreateObject(“Outlook.Application”) Do Until MyRS.EOF ‘Create the e-mail message. Set objOutlookMsg = objOutlook.CreateItem(olMailItem) TheAddress = “[FAX: ” & str_ToFaxName & “@” & Me.MYFaxToNum & “]” With objOutlookMsg ‘Add the To recipients to the e-mail message. Set objOutlookRecip = .Recipients.Add(TheAddress) objOutlookRecip.Type = olTo str_MyPath = “myPath” str_ToFaxName = Me.txt_To str_Report_Name = “rpt_2ndAttempt_MRR_FCS” str_MyFilename = str_ToFaxName & “_MRR.pdf” ‘Set the Subject, the Body, and the Importance of the e-mail message. .Body = “Please See Medical Record Request attachment” .subject = “HEDIS Medical Record Review–2nd Attempt” DoCmd.OutputTo acOutputReport, str_Report_Name, acFormatPDF, str_MyPath & “” & str_MyFilename, False str_myAttach = str_MyPath & “” & str_MyFilename ‘AttachmentPath = str_myAttach ‘Add the attachment to the e-mail message. If Not IsMissing(str_myAttach) Then Set objOutlookAttach = .Attachments.Add(str_myAttach) ‘(AttachmentPath) End If MsgBox str_myAttach ‘Resolve the name of each Recipient. For Each objOutlookRecip In .Recipients objOutlookRecip.Resolve If Not objOutlookRecip.Resolve Then objOutlookMsg.Display End If Next .Send Me.txt_HEDIS_Fax_Date_Attempt2 = Date End With MyRS.MoveNext Loop Set objOutlookMsg = Nothing Set objOutlook = Nothing End Sub