gpt4 book ai didi

email - 将电子邮件地址传递给 VBA 中的 SendObject 方法

转载 作者:行者123 更新时间:2023-12-02 05:03:02 25 4
gpt4 key购买 nike

我想从我的表“GetContact_TempTbl”中获取电子邮件地址并将报告发送到该电子邮件地址。此电子邮件将根据收到的公司而变化。我目前提取相关电子邮件地址并将其存储在临时表中. 我目前收到 Object Required 错误。

非常感谢您的建议。

Dim db As Database
Dim rs As Recordset
Dim stRecipients As String
Dim stDocName As String

Set db = CurrentDb()
Set rs = db.OpenRecordset("GetContact_TempTbl")
Set stRecipients = rs.Fields("Contact_Email")
stDocName = "License CODs"
stRecipietns = stRecipients

DoCmd.SendObject acReport, stDocName, acFormatPDF, stRecipients, , , "Thank You for your purchase"

最佳答案

如果您的记录集为您要发送电子邮件的每个收件人保留一行,请遍历记录集以收集它们,而不是只读取第一行的收件人。

Const stDocName As String = "License CODs"
Dim db As DAO.database
Dim rs As DAO.Recordset
Dim stRecipients As String

Set db = CurrentDb()
Set rs = db.OpenRecordset("GetContact_TempTbl")
With rs
Do While Not .EOF
stRecipients = stRecipients & ";" & !Contact_Email
.MoveNext
Loop
.Close
End With

If Len(stRecipients) > 0 Then
' discard leading ";"
stRecipients = Mid(stRecipients, 2)
DoCmd.SendObject acReport, stDocName, acFormatPDF, _
stRecipients, , , "Thank You for your purchase"
Else
MsgBox "No recipients to email!"
End If

Set rs = Nothing
Set db = Nothing

但是,如果我的解释不正确,并且记录集总是包含只有一个 Contact_Email 的一行,那么您甚至不需要记录集。您可以使用 DLookup 简单地检索 Contact_Email

stRecipients = Nz(DLookup("Contact_Email", "GetContact_TempTbl"), "")

关于email - 将电子邮件地址传递给 VBA 中的 SendObject 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14469957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com