Results 1 to 5 of 5

Thread: [RESOLVED] Run-time error '424': Object required VB6

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    3

    Resolved [RESOLVED] Run-time error '424': Object required VB6

    Good afternoon. I'm pretty rubbish at VB6. I'm OK at VBA but can't get a handle on this yet. I took some code from 'another' web site - http://www.kdkeys.net/forums/thread/868.aspx (I know, but I had to start somewhere) - and after some fiddling got it to work, nearly. It falls over at the following line:-
    Code:
    label1.Caption = .Fields("formid").Value & vbCrLf & .Fields("form name").Value & vbCrLf
    All I’m trying to do is start finding about connecting to a database from VB6. Here’s the complete code that I copied:-
    Code:
    Dim sConn As String 'for the connection string
    
    'now we declare the ADODB connection
    
    'to be able to show this NEW ADODB.Connection line, you must do the following:
    
    '1. in the toolbox, you must add a component.
    '2. in the component box, find the Microsoft ActiveX ADO connection something like that.
    '3. then when this is done, drag the component into your form and then delete it
    '4. this way you may be able to have the NEW ADODB line in your intellisense
    
    'now lets proceed to connecting you db and vb6.0
    
    Dim db As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim sPath As String ' here we put the path of your database
    Dim sSQL As String 'your SQL Statement
    
    
    'now let us proceed to the main part
    
    
    Private Sub Command1_Click()
    
    sPath = "D:\Formscape\database\formscape.mdb"
    
    'initialize the connection string
    
    sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPath
    
    sSQL = "SELECT * FROM forms"
    
    
    db.ConnectionString = sConn
    db.Open
    
    With rs
    .ActiveConnection = db
    .LockType = adLockOptimistic
    .CursorType = adOpenKeyset
    .Open sSQL
    
    ' now let us loop through your records and show it to your label
    ' for example your table has two fields, the field called name and description
    
    Do While Not .EOF
    label1.Caption = .Fields("formid").Value & vbCrLf & .Fields("form name").Value & vbCrLf
    
    .MoveNext
    Loop
    
    'let close the rs connection
    rs.Close
    End With
    Set rs = Nothing
    db.Close
    Set db = Nothing
    End Sub
    Any help will be gratefully received. Many thanks, Des.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Run-time error '424': Object required VB6

    Welcome to VBForums

    The error is caused by there not being a label control called Label1 on your form, which should have been mentioned by the person who posted it. However, that is not the only thing that is a problem.

    I would recommend not using that code (and definitely not the advice to add a component), as there are at least 4 things in it that are badly designed/coded - which will lead to errors or odd behaviour (for example, you will only see data from the last record).

    What I recommend instead is to take a look at the "Classic VB: ADO" section of our Database Development FAQs/Tutorials (at the top of the Database Development forum), particularly the "ADO Tutorial" - which doesn't have the same kind of issues, and explains the different parts of the code to you.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    3

    Re: Run-time error '424': Object required VB6

    Top man Si, thanks. Until you're as ignorant as me (?) you wouldn't believe how difficult it was to get such basic information as this from anywhere. I'll give your suggestion a go in a minute. I'll let everyone know how it went!

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    3

    Re: Run-time error '424': Object required VB6

    OK, I managed to do that just fine. It feels really good to find code that works (http://www.vbforums.com/showthread.php?t=551154) - just having to amend slightly to suit my data/path etc. Many thanks. Des.

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Run-time error '424': Object required VB6

    Now that we've helped you, you can help us by marking the thread as resolved. If you have JavaScript enabled you can do that easily by pulling down the Thread Tools menu and selecting the Mark Thread Resolved item. Also if someone has been particularly helpful you have the ability to affect their forum "reputation" by rating their post. Only those ratings that you give after you have 20 posts will actually count, but in all cases the person you rate will see your rating and know that you appreciate their help.

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