我试图做一个函数,以便它发送一封电子邮件到我的查询(UpcomingBirthday)中的一个电子邮件地址。我有一个函数中的代码,然后在宏自动执行,所以它运行时,我加载我的数据库。'Object Required'to send Email
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") = "[email protected]"
flds.Item(schema & "sendpassword") = "MyPassword"
flds.Item(schema & "smtpusessl") = False
flds.Update
With imsg
Call EmailSend(UpcomingBirthday.[Email], "[email protected]", "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 [邮件] ,“[email protected]”,“生日促销!”,等等。所以我需要做的是从我的查询'UpcomingBirthday'中'Email'列中的值,然后发送一封电子邮件给他们。
如果有人能告诉我我需要做什么来解决这个错误,那会很棒!还有,如果你只是扫描代码,看看它是否正常(如应该它工作)? !:)
是你在你的代码中使用递归计划?你将函数定义为'Public Function EmailSend()',该函数中的一个语句是'Call EmailSend'。当一个过程('Sub'或'Function')在没有任何退出条件的情况下自行调用时,事情往往会“变得糟糕”。 – 2013-04-08 22:36:08
如果我将'Call EmailSend'更改为'Call SendEmail',它表示* Sub或Function not defined *。所以是的,我认为递归是故意的?我认为问题出现在'即将到来的生日'内[电子邮件]' – 2013-04-08 22:41:13