对象必需 - 错误424 MS ACCESS 2010

时间:2015-11-12 10:14:48

标签: object access-vba required

我在VBA上真的很新,但我在另一个数据库中有相同的代码,现在我只是复制了代码并粘贴到另一个数据库中,但我在最后一行得到了这个Object Required错误。 代码更大但我刚刚停在我收到错误的行上。

 Dim frm As Form, ctl As Control
 Dim varItm As Variant
 Dim stgMO, stgPID, stMail, stgMailCC As String
 Dim Question As Long
 Dim OutApp, OutMail As Object

 Set frm = Forms!Overview
 Set ctl = frm!cl_onboarding

 stgMO = ctl.Column(7)
 stgPID = ctl.Column(2)
 stgMail = ctl.Column(8)
 stgMailCC = ctl.Column(9)

Question = MsgBox("Do you want to send an e-mail containing the codes for this Agent?", vbYesNo, "Send e-mail")
If Question = vbYes Then

    Set OutApp = Outlook.Application

2 个答案:

答案 0 :(得分:0)

You need to set a Reference in VBA to Outlook.

VBA editor -> menu Tools -> References

Select and check Microsoft Outlook 14.0 Object Library

Edit: while the above is true, you would probably get a different error if the reference was missing.

The problem may be in this line:

Dim OutApp, OutMail As Object

which actually gets evaluated as

Dim OutApp As Variant, OutMail As Object

and should read

Dim OutApp As Object, OutMail As Object

But a Variant can hold an object too, so this may also not be the cause of the error.

答案 1 :(得分:0)

您将dim stMail作为变量,然后使用stgMail。只需检查你的拼写。

你也使用dim question as long,这让我感到困惑,因为我认为long意味着一个整数(有最小值和最大值,但我不记得)。