我正在尝试创建一个功能,以便它将电子邮件发送到我的一个查询(即将到来的生日)中的电子邮件地址。我将这段代码放在一个函数中,然后放在一个宏 autoexec 中,以便在我加载数据库时运行。
Public Function EmailSend()
Dim imsg As Object
Dim iconf As Object
Dim flds As Object
Dim schema As String
Set imsg = CreateObject("CDO.Message")
Set iconf = CreateObject("CDO.Configuration")
Set flds = iconf.Fields
schema = "http://schemas.microsoft.com/cdo/configuration/"
flds.Item(schema & "sendusing") = cdoSendUsingPort
flds.Item(schema & "smtpserver") = "smtp.live.com"
flds.Item(schema & "smtpserverport") = 25
flds.Item(schema & "smtpauthenticate") = cdoBasic
flds.Item(schema & "sendusername") = "MyEmail@hotmail.com"
flds.Item(schema & "sendpassword") = "MyPassword"
flds.Item(schema & "smtpusessl") = False
flds.Update
With imsg
Call EmailSend(UpcomingBirthday.[Email], "MyEmail@hotmail.com", "Birthday Promotion!", "<html>Happy Birthday! <p> Our records indicate that you're eligible for a birthday promotion.</p></html.")
Set .Configuration = iconf
.Send
End With
Set iconf = Nothing
Set imsg = Nothing
Set flds = Nothing
End Function
现在,当我尝试运行此代码时,它会告诉我“运行时错误 424 - 需要对象”,并在我转到 Debug 时突出显示这一行:Call EmailSend(UpcomingBirthday.[Email], "MyEmail@hotmail.com", "生日促销!”等等。所以我需要它做的是查询“即将到来的生日”中“电子邮件”列中的值,然后向他们发送电子邮件。
如果有人可以通过告诉我需要做什么来解决此错误来帮助我,那就太好了!另外,如果您可以扫描代码并查看它是否正常(就像它应该工作一样)?谢谢!:)