我正在尝试创建一个函数,以便它向我的一个查询(UpcomingBirthday)中的电子邮件地址发送电子邮件。我在函数中有这个代码,然后在宏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 - 需要对象”并在我进入调试时突出显示此行:调用EmailSend(UpcomingBirthday。 [电子邮件],“MyEmail@hotmail.com”,“生日促销!”,等。所以我需要它做的是我的查询'UpcomingBirthday'中的'Email'栏中的值然后发送电子邮件给他们。
如果有人可以通过告诉我我需要做些什么来帮助我来解决这个错误,那就太好了!如果你只是扫描代码并查看它是否正常(如果它可以工作)?谢谢! :)
答案 0 :(得分:0)
Call EmailSend
中的Public Function EmailSend
声明显然存在问题。如果要为imsg
(CDO.Message
对象)的属性赋值,那么只需执行类似
With imsg
.To = "recipient@example.com"
.From = "MyEmail@hotmail.com"
.Subject = "Birthday Promotion!"
'' and so on
.Send
End With
另外,我们不知道UpcomingBirthday
究竟是什么,因为它是在其他地方定义的。
您可能希望省去一些麻烦,只需使用可在此处下载的SendEmail
功能: