单击命令button时,对象所需的错误

尝试访问我的用户表单时收到“Object required”错误。 它突出显示了以下代码:

Sub DataEntry() ServiceUpgradesDatEntry.Show End Sub 

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

转到VBE中的Tools - Options - General ,并将错误陷阱更改为Break in Class Module 。 在用户窗体的Initialize事件中有一个错误,但VBE没有被设置为在用户窗体的类模块中断开,所以它在发送给类模块(.Show行)的那一行中断了。

一旦你设置了,点击错误debugging将突出显示实际上产生错误的行。

像对象一样对待你的用户表单,并相应地声明和实例化它。

 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