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