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
|