Aaron
Aaron

Reputation: 1989

What does this VB6 error mean?

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

Upvotes: 0

Views: 851

Answers (6)

jakdep
jakdep

Reputation: 872

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

Upvotes: 1

Matt Wilko
Matt Wilko

Reputation: 27322

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

Upvotes: 1

Hrqls
Hrqls

Reputation: 2951

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

Upvotes: 1

Arvo
Arvo

Reputation: 10570

You have not initialized datPersonal.Recordset.

Upvotes: 2

tamasgal
tamasgal

Reputation: 26259

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

Upvotes: 2

mdm
mdm

Reputation: 12630

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.

Upvotes: 1

Related Questions