2015-05-19 81 views
0

尝试访问我的用户表单时收到“Object required”错误。它突出显示以下代码:单击命令按钮时出现对象所需的错误

Sub DataEntry() 
    ServiceUpgradesDatEntry.Show 
End Sub 

我已经仔细检查名称是否正确。我还是新来的VBA,所以任何帮助将不胜感激!

回答

1

转到在VBE和改变错误捕获Tools - Options - GeneralBreak in Class Module。在用户窗体的Initialize事件中有一个错误,但VBE没有设置为在用户窗体的类模块中断开,所以它在发送给类模块(.Show行)的线上断开。

设置完成后,单击错误上的调试将突出显示实际产生错误的行。

1

将您的用户表单视为一个对象,并相应地声明并实例化它。

Public Sub DataEntry() 

    Dim dataEntryForm As ServiceUpgradesDatEntry 

    ' Create an instance of the form 
    Set dataEntryForm = New ServiceUpgradesDatEntry 
    ' Show the form 
    dataEntryForm.Show 
    ' If the form was opened as Modal, then the code here will only run 
    ' once the form has been hidden/closed 
    ' Now destroy the object 
    Set dataEntryForm = Nothing 

End Sub 
相关问题