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().