Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB6 grid
Everytime I press the command button , "error 424 Object required" is showing up
 

Public con1 As New ADODB.Connection
Public rs As New ADODB.Recordset
Dim q1 As String
Dim i As Integer
Public Sub con()
    con1.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = E:\TrainTimeSchedule.accdb"
    Set con1 = New ADODB.Connection
    con1.Open ("dsn123")
End Sub
Public Sub opentable(sql As String)
    Set rs = con1.Execute(sql)
End Sub
 
Private Sub Command1_Click()
    
    q1 = "Select TrainID,TrainName,Source,Destination,Stations,DayOfWeek from TrainTable Where Source ='" & tex1.Text & "'" & "and Destination = '" & Text2.Text & "')"
    opentable (q1)
    MSFlexGrid1.DataSource = rs
End Sub
Posted 20-Apr-13 21:34pm
Comments
ThePhantomUpvoter at 21-Apr-13 5:48am
   
Probably because you are never calling con() anywhere.
AlluvialDeposit at 23-Apr-13 8:48am
   
your code is vulnerable for sql-injections!

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi Please use follow of code for solve your problem:
 
Public adodbcon As New ADODB.Connection
Public adodbrs As New ADODB.Recordset
 

Public Sub opentable(sql As String)
    adodbcon .ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = E:\TrainTimeSchedule.accdb"
    Set adodbcon = New ADODB.Connection
    adodbcon.Open ("dsn123")
    Set adodbrs = adodbcon .Execute(sql)
End Sub
 
 
Private Sub Command1_Click()
Dim q1 as String    
    q1 = "Select TrainID,TrainName,Source,Destination,Stations,DayOfWeek from TrainTable Where Source =N'" & tex1.Text & "'" & "and Destination =N'" & Text2.Text & "')"
    opentable(q1)
    MSFlexGrid1.DataSource = rs
End Sub
 
Remember finally your should call adodbcon.Close() for closing adodb connection because adodb is connection base and if you don`t do it you will get error at the next using as adodb.Open().
  Permalink  
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 Afzaal Ahmad Zeeshan 152
2 ProgramFOX 130
3 Maciej Los 130
4 den2k88 80
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100