williamrojas78 11 Junior Poster

Hi all.

I have this ADO connection to an acces 97 database and I need to filter some of the data. I can connect and I can read and write to this database, but the filtering option is giving me a hard time.

I have tried but i don't know what i am doing wrong, it does not want to work.

Here is the code, thanks in advance

Public conConnection As New ADODB.Connection
Public cmdCommand As New ADODB.Command
Public rstRecordset As New ADODB.Recordset


Sub test_filter()

Dim rstStartevents As Recordset
Dim filds As String

openCon                  ' opens connection (see below)


filds = rstRecordset.Fields.Item(3).Name    'retrieves the name of the 3rd field
Set strStartevents = FilterField(rstRecordset, filds, "Start")     ' function below

closeCon                 'closes the connection

End Sub


'*************************************

Public Function FilterField(rstTemp As Recordset, _
   strField As String, strFilter As String) As ADODB.Recordset

  
   rstTemp.Filter = strField & " = '" & strFilter & "'"
   FilterField = rstTemp

End Function


'*******************************


Function openCon()


conConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
    App.Path & "\" & "database.mdb;Mode=Read|Write"

conConnection.CursorLocation = adUseClient
conConnection.Open


    With cmdCommand
        .ActiveConnection = conConnection
        .CommandText = "SELECT * FROM Table1;"   
        .CommandType = adCmdText
    End With



    With rstRecordset
        .CursorType = adOpenStatic
        .CursorLocation = adUseClient
        .LockType = adLockOptimistic
        .Open cmdCommand
    End With


End Function