MS Access:从记录集发送到多个电子邮件地址的电子邮件

时间:2016-01-09 19:42:41

标签: vba email access-vba

团队:我正在尝试向特定表格中的所有收件人发送电子邮件。代码正在打开正确的记录集,但是当电子邮件打开时,只有记录集中的最后一条记录显示在“收件人:”字段中。我已经研究过这个网站,并根据这里的调查结果使用了一些不同的代码,但仍然不够智能,无法实现这一目标。任何回应将不胜感激。提前谢谢。

Dim OObj As Outlook.Application
Dim OMsg As Outlook.MailItem
Dim db As Database
Dim rs As Recordset
Dim EmailAddress As String
    Set OObj = CreateObject("Outlook.Application")
    Set OMsg = OObj.CreateItem(olMailItem)
    Set db = CurrentDb
    Set rs = db.OpenRecordset("65_EmailGroupADMIN_T")
    With rs

    If .EOF And .BOF Then
        MsgBox "No emails will be sent because there are no records assigned from the list", vbInformation
        Else
        Do Until .EOF
            EmailAddress = ![Email]
            .Edit
            .Update
            OMsg.To = EmailAddress
            .MoveNext
        Loop
    OMsg.Display
End If
End With
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Set OMsg = Nothing
Set OObj = Nothing

End Sub

1 个答案:

答案 0 :(得分:0)

您正在使用循环中的当前EmailAddress删除您的TO收件人。您应该将变量中的所有地址重新连接起来。 另外,我认为您的rs.updaters.edit说明没有任何目的......

请改为:

With rs

If .EOF And .BOF Then
    MsgBox "No emails will be sent because there are no records assigned from the list", vbInformation
    Else
    EmailAddress = ""
    Do Until .EOF
        EmailAddress = EmailAddress & ";" & ![Email]
        .MoveNext
    Loop

    OMsg.To = EmailAddress
    OMsg.Display

    End If

End With