Filtering a Recordset by using the Date type field : Recordset Filter « Access « VBA / Excel / Access / Word






Filtering a Recordset by using the Date type field

 
Sub FilterRecordset()
    Dim rst As ADODB.Recordset
    Set rst = New ADODB.Recordset

    rst.ActiveConnection = CurrentProject.Connection
    rst.CursorType = adOpenKeyset
    rst.LockType = adLockOptimistic
    rst.Open "Select * from Employees"

    Debug.Print "Without Filter"
    Do Until rst.EOF
        Debug.Print rst("BirthDate")
        rst.MoveNext
    Loop

    rst.Filter = "BirthDate >= #1/1/1977# and BirthDate <= #1/5/2007#"
    Debug.Print "With Filter"
    Do Until rst.EOF
        Debug.Print rst("BirthDate")
        rst.MoveNext
    Loop

    rst.Close
    Set rst = Nothing
End Sub

 








Related examples in the same category

1.Use Recordset filter
2.Get result set by column name
3.Filtering Records Using the Filter Property
4.Filtering Records with an SQL Clause
5.Get the number of recorders which meet the criteria
6.Filtering a Recordset