HandsOn Filtering Records Using the Filter Property

1. In the Code window, enter the FltrRecords procedure as shown below.

Sub FltrRecords()

Dim conn As ADODB.Connection Dim rst As ADODB.Recordset

Set conn = New ADODB.Connection conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & CurrentProject.Path & _ "\Northwind.mdb"

Set rst = New ADODB.Recordset With rst

Part II

.Open "Customers", conn, adOpenKeyset, adLockOptimistic .Filter = "City='Madrid' and Country='Spain'" MsgBox .RecordCount & " records meet the criteria.", _ vbInformation, "Customers in Madrid (Spain)" End With

Do Until rst.EOF

Debug.Print rst.Fields(1).Value rst.MoveNext Loop rst.Filter = adFilterNone

MsgBox "Filter was removed. " & vbCr _

& "The table contains " & rst.RecordCount & " records."

rst.Close Set rst = Nothing conn.Close Set conn = Nothing End Sub

0 0

Post a comment