首页 > 解决方案 > MS Access - 记录集 - 循环遍历表并发送电子邮件 - 得到“运行时错误 440:数组索引超出范围

问题描述

我有一个表单,其中包含我希望我的代码循环并发送个人电子邮件的人员列表。我以前做过,但不知何故我忽略了一些东西。我在表单中使用的主要变量是 NAME(我正在发送电子邮件的人的姓名)和 EMAIL(电子邮件地址)。不知道为什么我得到 Array Index Out of Bounds 错误,但希望这是一个简单的修复。任何帮助表示赞赏!


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

标签: vbadatabasems-accessdaoms-access-forms

解决方案


推荐阅读