这个 VB6 错误是什么意思?

发布于 2024-10-31 07:02:58 字数 843 浏览 1 评论 0原文

运行时错误'91':

对象变量或With块变量未设置

我正在使用VB6

OK这是我的代码

Private Sub Form_Load()
    lblIDNumber.Caption = UserID

    With datPersonal.Recordset
        .Index = "idxid"
        .Seek "=", UserID

        LockTextboxes

    End With

End Sub

Public Sub LockTextboxes()
    With txtDateHired
        .Locked = True
    End With

    With txtBirthday
        .Locked = True
    End With

    With txtGender
        .Locked = True
    End With

    With txtAddress
        .Locked = True
    End With

    With txtContact
        .Locked = True
    End With

    With txtStatus
        .Locked = True
    End With

    With txtPosition
        .Locked = True
    End With

    With txtBasicSalary
        .Locked = True
    End With

    With txtReligion
        .Locked = True
    End With
End Sub

Run Time Error '91':

Object variable or With block variable not set

I am using VB6

OK here is my code

Private Sub Form_Load()
    lblIDNumber.Caption = UserID

    With datPersonal.Recordset
        .Index = "idxid"
        .Seek "=", UserID

        LockTextboxes

    End With

End Sub

Public Sub LockTextboxes()
    With txtDateHired
        .Locked = True
    End With

    With txtBirthday
        .Locked = True
    End With

    With txtGender
        .Locked = True
    End With

    With txtAddress
        .Locked = True
    End With

    With txtContact
        .Locked = True
    End With

    With txtStatus
        .Locked = True
    End With

    With txtPosition
        .Locked = True
    End With

    With txtBasicSalary
        .Locked = True
    End With

    With txtReligion
        .Locked = True
    End With
End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

不必在意 2024-11-07 07:02:58

当您调用未设置的对象的方法时,通常会发生这种情况。

It usually occurs when you call a method of an object which is not set.

留蓝 2024-11-07 07:02:58

您尚未初始化 datPersonal.Recordset。

You have not initialized datPersonal.Recordset.

污味仙女 2024-11-07 07:02:58

这意味着您正在尝试使用变量,但尚未将该变量设置为任何值。具体来说,变量引用对象而不是值类型。

通常的原因是执行诸如 Dim obj As SomeClass 而不是 Dim obj As New SomeClass 之类的操作,即在使用变量之前未能将变量设置为对对象的引用。

It means you are trying to use a variable, but haven't set the variable to any value. Specfically, the variable references an object rather than a value type.

Usual cause is doing something like Dim obj As SomeClass rather than Dim obj As New SomeClass, i.e. failing to set the variable to a reference to an object before using it.

小嗷兮 2024-11-07 07:02:58

也许问题已经以另一种方式解决了,但是您可以尝试将代码从 form_load 移至 form_activate

maybe the problem was solved already in another way, but you could try to move the code from form_load to form_activate

满天都是小星星 2024-11-07 07:02:58

您需要先初始化类,然后才能使用它们。假设 datPersonal.Recordset 实际上是一个 Recordset 类,那么您需要执行如下操作:

Set datPersonal.Recordset = New ADODB.Recordset

您还需要确保已添加对项目中 ActiveX 数据对象的引用。

查看以下内容:

添加对 ADO 的引用

使用记录集

You need to initialise classes before they can be used. Assuming datPersonal.Recordset is actually a Recordset class then you will need to do something like the following:

Set datPersonal.Recordset = New ADODB.Recordset

You also need to make sure that you have added a reference to the ActiveX Data Objects in you project.

Have a look at the following:

Add reference to ADO

Using a recordset

没有伤那来痛 2024-11-07 07:02:58

根据您之前的问题,我假设 datPersonal 指的是 ADO Datacontrol。
数据控件的连接字符串和选择标准可以在设计时设置,并且当应用程序启动时,会自动打开连接和记录集。

您收到此错误的事实表明未指定连接字符串和选择或者执行了以下代码:

Set datPersonal.Recordset = Nothing

From your previous questions I am assuming that the datPersonal refers to a ADO Datacontrol.
The connectionstring and selection criteria of the datacontrol can be set at design-time and when the application is started, a connection and recordset is automatically opened.

The fact that you are getting this error indicates either that the connectionstring and selection was not specified or that the following code was executed :

Set datPersonal.Recordset = Nothing
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文