使用VBA发送电子邮件'函数运行时错误438'

时间:2013-07-30 08:09:58

标签: smtp access-vba runtime-error

我正在尝试使用VBA代码发送电子邮件,该功能正在运行并且电子邮件已发送,但问题是当功能结束时'运行时错误438对象不支持此属性或方法'出现

这是代码:

Public Function SendEmail(ItemName As String, Total_Qnty As Integer)

 Set iMsg = CreateObject("CDO.Message")

 Set iConf = CreateObject("CDO.Configuration")

 Set Flds = iConf.Fields

 ' send one copy with Google SMTP server (with autentication)

 schema = "http://schemas.microsoft.com/cdo/configuration/"

 Flds.Item(schema & "sendusing") = 2

 Flds.Item(schema & "smtpserver") = "smtp.gmail.com"

 Flds.Item(schema & "smtpserverport") = 465

 Flds.Item(schema & "smtpauthenticate") = 1

 Flds.Item(schema & "sendusername") = "example@gmail.com"

 Flds.Item(schema & "sendpassword") = "*****"

 Flds.Item(schema & "smtpusessl") = 1

 Flds.Update


 With iMsg

     .To = "example@hotmail.com"

     .From = "example@gmail.com"

     .Subject = "Mail from gmail"

     .HTMLBody = "The Stock Safty Level of Item: " & ItemName & " is DOWN, The total      quantity you have is: " & Total_Qnty & "!!"

     Set .Configuration = iConf

     .Send

 End With


 Set iMsg = Nothing

 Set iConf = Nothing

 Set Flds = Nothing


End Function

高兴任何想法..谢谢

2 个答案:

答案 0 :(得分:0)

很可能这是组件之间的二进制兼容性问题。

Microsoft说“运行时错误438 - 对象不支持此属性或方法: 导致错误438的最常见原因是不保持组件的连续版本之间的二进制兼容性。每个COM接口都有一个关联的GUID,称为接口ID(IID)。每个coclass都有一个关联的GUID,称为类ID(CLSID)。在Visual Basic中编译ActiveX组件时,CLSID和IID将编译到组件的类型库中。

在此链接中,它解释了如何解决类似的问题:

http://www.vbforums.com/showthread.php?460591-RESOLVED-Runtime-error-438-Object-doesn-t-support-this-property-or-method

答案 1 :(得分:0)

颠倒这些的顺序:

Set iMsg = Nothing

Set iConf = Nothing

Set Flds = Nothing

Flds是iConf的成员,目前您已经处理过。