MS Access - Recordset - Looping through table and sending emails - getting "Run Time Error 440: Array Index Out of Bounds

90 views Asked by At

I have a form that has a list of people that I want my code to loop through and send individual emails. I've done this before, but somehow I am overlooking something. The main variables I am using in my form are NAME (the name of the person I am emailing) and EMAIL (the email address). Not sure why I am getting the Array Index Out of Bounds error, but hopefully it's a simple fix. Any help is appreciated!


Set OutApp = CreateObject("Outlook.Application")

Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("My_Table")

With rs

    If .EOF And .BOF Then

        MsgBox "No emails will be sent becuase there are no records assigned from the list", vbInformation

    Else

        Do Until .EOF

            stremail = Me![Email] 'This is the list of people's email addresses I want to email

            strsubject = "the subject - placeholder for now"

            strbody = "Dear " & Me![Name] & "Hello and goodbye."

 

            Set OutMail = OutApp.CreateItem(olMailItem)

            With OutMail

                .To = stremail

                .CC = ""

                .BCC = ""

                .Subject = strsubject

                .Body = strbody

 

                .SendUsingAccount = OutApp.Session.Accounts.Item(2)

                .Send

            End With

            .MoveNext

        Loop

    End If

End With

End Sub
0

There are 0 answers