Use Recordset filter : Recordset Filter « Access « VBA / Excel / Access / Word






Use Recordset filter

 

Sub TestFilter()
    Dim rsContacts As ADODB.Recordset
    Set rsContacts = New ADODB.Recordset
    With rsContacts
        .CursorType = adOpenStatic
        .Open "tblContacts", CurrentProject.Connection
    End With
    rsContacts.Filter = "txtLastName Like 'D*'"
    If rsContacts.EOF Then
        Debug.Print "No records met that criteria."
    Else
        Do Until rsContacts.EOF
            Debug.Print "Contact Id: " & rsContacts!intContactId & _
                "  Last Name: " & rsContacts!txtLastName & _
                "  First Name: " & rsContacts!txtFirstName
            rsContacts.MoveNext
        Loop
    End If
    rsContacts.Close
    Set rsContacts = Nothing
End Sub

 








Related examples in the same category

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