Run - time error '91' Object variable or With block variable not set 
Author Message
 Run - time error '91' Object variable or With block variable not set

Hi,
In my form that the users do a login, it works in my older version,
but when I changed the design of my program and instead of using
command button, I change to a label, this error occur..
It's the same code, I don't know where's the problem... :(
does anyone know what's wrong with this code?
Thanks!

    Pucca

Option Explicit
Dim Cn As ADODB.Connection
Dim Rs As ADODB.Recordset
Dim Rs2 As ADODB.Recordset
Dim username, user, password As String
Dim r, p, user_existe, password_incorrecta As Integer

Private Sub Lbl3_Click()
password_incorrecta = 0
user_existe = 0
Rs.MoveFirst --> error here (Run - time error '91' Object variable or
With block variable not set)

If Rs.RecordCount > 0 Then
    For p = 0 To Rs.RecordCount - 1
    username = Rs("nome")
    password = Rs("password")

    If username = Txt1.Text Then
       If (StrComp(password, Txt2.Text)) = 0 Then
        user_exist = 1
    Else
        password_incorrect = 1
    End If
End If
Rs.MoveNext
Next p
End If

    If password_incorrect = 1 Then
        r = MsgBox("Password incorrect", vbOKOnly + vbCritical,
"Login")
    Else
    If user_exist <> 1 Then
        r = MsgBox("Username incorrect", vbOKOnly + vbCritical,
"Login")
    Else
        If Txt1.Text = "administrador" Then
        Unload Me
        Call Frmnovo.Show
        Else
        If Txt1.Text <> "administrador" Then
        user = Txt1.Text
        Unload Me
        Call Frmmenu.Show
        Set Rs2 = New ADODB.Recordset
        Rs2.CursorLocation = adUseClient
        Rs2.Open "historico", Cn, adOpenDynamic, adLockOptimistic,
adCmdTable
        Rs2.AddNew
    Rs2.Fields("username") = user
    Rs2.Fields("data") = Date
    Rs2.Fields("hora") = Time
    Rs2.Update
    Rs2.Close
    Set Rs2 = Nothing
    End If
    End If
    End If
    End If
    Rs.Close
Set Rs = Nothing
Cn.Close
Set Cn = Nothing
End Sub

Private Sub Form_Load()
'Connecting to a database
    Set Cn = New ADODB.Connection
    Cn.ConnectionString = "provider=Microsoft.jet.oledb.4.0;Data
Source=\\Sw2\gestmail\gestmail.mdb"
    Cn.Open
    Set Rs = New ADODB.Recordset
    Rs.CursorLocation = adUseClient
    Rs.Open "SELECT * FROM login", Cn, adOpenDynamic
End Sub



Tue, 25 Oct 2005 22:48:08 GMT  
 Run - time error '91' Object variable or With block variable not set
Hi,

That error means that your recordset variable is set to Nothing. Basically
recordset is not opened and you try to use methods of it

--
Val Mazur
Microsoft MVP


Quote:
> Hi,
> In my form that the users do a login, it works in my older version,
> but when I changed the design of my program and instead of using
> command button, I change to a label, this error occur..
> It's the same code, I don't know where's the problem... :(
> does anyone know what's wrong with this code?
> Thanks!

>     Pucca

> Option Explicit
> Dim Cn As ADODB.Connection
> Dim Rs As ADODB.Recordset
> Dim Rs2 As ADODB.Recordset
> Dim username, user, password As String
> Dim r, p, user_existe, password_incorrecta As Integer

> Private Sub Lbl3_Click()
> password_incorrecta = 0
> user_existe = 0
> Rs.MoveFirst --> error here (Run - time error '91' Object variable or
> With block variable not set)

> If Rs.RecordCount > 0 Then
>     For p = 0 To Rs.RecordCount - 1
>     username = Rs("nome")
>     password = Rs("password")

>     If username = Txt1.Text Then
>        If (StrComp(password, Txt2.Text)) = 0 Then
>         user_exist = 1
>     Else
>         password_incorrect = 1
>     End If
> End If
> Rs.MoveNext
> Next p
> End If

>     If password_incorrect = 1 Then
>         r = MsgBox("Password incorrect", vbOKOnly + vbCritical,
> "Login")
>     Else
>     If user_exist <> 1 Then
>         r = MsgBox("Username incorrect", vbOKOnly + vbCritical,
> "Login")
>     Else
>         If Txt1.Text = "administrador" Then
>         Unload Me
>         Call Frmnovo.Show
>         Else
>         If Txt1.Text <> "administrador" Then
>         user = Txt1.Text
>         Unload Me
>         Call Frmmenu.Show
>         Set Rs2 = New ADODB.Recordset
>         Rs2.CursorLocation = adUseClient
>         Rs2.Open "historico", Cn, adOpenDynamic, adLockOptimistic,
> adCmdTable
>         Rs2.AddNew
>     Rs2.Fields("username") = user
>     Rs2.Fields("data") = Date
>     Rs2.Fields("hora") = Time
>     Rs2.Update
>     Rs2.Close
>     Set Rs2 = Nothing
>     End If
>     End If
>     End If
>     End If
>     Rs.Close
> Set Rs = Nothing
> Cn.Close
> Set Cn = Nothing
> End Sub

> Private Sub Form_Load()
> 'Connecting to a database
>     Set Cn = New ADODB.Connection
>     Cn.ConnectionString = "provider=Microsoft.jet.oledb.4.0;Data
> Source=\\Sw2\gestmail\gestmail.mdb"
>     Cn.Open
>     Set Rs = New ADODB.Recordset
>     Rs.CursorLocation = adUseClient
>     Rs.Open "SELECT * FROM login", Cn, adOpenDynamic
> End Sub



Tue, 25 Oct 2005 23:13:10 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Run Time Error 91: Object variable or With Block variable not set

2. Run-time error '91' Object variable or With block variable not set

3. Object variable or With block variable not set (Error 91)

4. error 91 Object Variable o on with block variable is not set

5. Runtime error 91/Object variable or With block variable not set problems

6. runtime error: 91 Object variable or with block variable not set

7. Object variable or With block variable not set (Error 91) Please Help

8. VB 5.0 - Error:91 Object Variable Or With Block Variable Not Set

9. Object variable or With block variable not set (Error 91)

10. Error 91 Object variable or With-Block, variable not set

11. Object Variable not set , Run Time error 91, please Help

12. Run Time Error 91: Object Variable not set.....

 

 
Powered by phpBB® Forum Software