CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2009
    Posts
    3

    VB6 Runtime Error 91

    I'm doing a coursework project using Visual Basic 6, and I simply can't get the Login form to work. On my tutpor's reccomendation, I'm using an Adodc controller with the Jet 4.0 engine to connect to a database containing usernames, passwords and access levels for users. The connection works fine and I've tested it out, but I'm getting Runtime Error 91 every time I run the Logon form. Here's the code I'm using:

    Code:
    Private Sub Cancel_Button_Click()
    
        Unload Me
    
    End Sub
    
    Private Sub Login_Button_Click()
    
        'Runtime 91 Error happens on the Line Below
        If (Adodc1.Recordset(0) = txtUserName.Text And Adodc1.Recordset(1) = txtPassword.Text) Then
            frmRolfs.Show
            Unload Me
    
        Else
    
            msgError.Caption = "Username or Password Incorrect"
    
        End If
    
    End Sub
    Any advice would be appreciated!

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: VB6 Runtime Error 91

    It would help if you gave the description of the error message rather than just the number.

    I would not use the data control but would use ado code instead.

    You have not shown where you are opening a recordset.

  3. #3
    Join Date
    Jun 2009
    Posts
    3

    Re: VB6 Runtime Error 91

    the exact error code is "Object variable or With block variable not set."

    Also, forgive my ignorance, but I don't know how to sue ADO code or open a recordset. I have very limited knowledge of visual basic and am trying to follow my tutor's instructions.

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: VB6 Runtime Error 91

    Shouldn't it be :
    Code:
    Adodc1.Recordset(0).Value = txtUserName.Text And Adodc1.Recordset(1).Value = txtPassword.Text) Then
    ...

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: VB6 Runtime Error 91

    Value is the default property and can be omitted in this instance.

    The error indicates either the recordset is not initialized or one of the text boxes referenced does not exist by the name specified. My money is on the recordset object.


    For an example on how to use ado code rather than the control use the data form wizard inside vb and choose ado code. This will generate the code to create the connection and the recordset object, connect to the database and initialize the recordset.

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB6 Runtime Error 91

    Read the article that I wrote (the link is in my signature). You can download a functional program that doesn't bind data to a grid.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: VB6 Runtime Error 91

    Quote Originally Posted by DataMiser View Post
    Value is the default property and can be omitted in this instance.
    Yes, I agree. It makes much more sense having it there, for readability purposes, and normal protocol ( if you may ).

  8. #8
    Join Date
    Jun 2009
    Posts
    3

    Re: VB6 Runtime Error 91

    I'm still having trouble initializing the recordset function. I have no idea how to do it- can anyone point me in the right direction?

  9. #9
    Join Date
    Apr 2009
    Posts
    394

    Re: VB6 Runtime Error 91

    It is bad programming practice to leave the property off of anything... Period... even if it is current form...

    Nuff Said?!?! (Let's see you become team leader/head programmer and see the looks on their faces when you send their code back because of this sloppy programming practice)

  10. #10
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB6 Runtime Error 91

    Did you look at my code? It is well-explained (based on feedback) and it WORKS. (Imagine that!)

    If you can't see how I open a recordset, just press F8 to run the program, and step thru it line by line. Or else, press F9 on a line to set a BREAK POINT, and you can run up to that point, and then STEP thru the code.

    You can see the actual value of variables by hovering the mouse while in DEBUG mode (stepping thru)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured