ADO

Filtering with Bookmarks

Finally, you can pass a variant array of bookmarks to the Filter property. The resulting cursor will contain only those records whose bookmark was passed in to the property. The following code example creates an array of bookmarks from the records in a Recordset which have a "B" in the ProductName field. It then passes the array to the Filter property and displays information about the resulting filtered Recordset.

'BeginFilterBkmk
Dim vBkmkArray() As Variant

Dim i As Integer
i = 0

'Recordset created using "SELECT * FROM Products" as command.
'So, we will check to see if ProductName has a capital B, and
'if so, add to the array.
Do While Not objRs.EOF
    If InStr(1, objRs("ProductName"), "B") Then
        ReDim Preserve vBkmkArray(i)
        vBkmkArray(i) = objRs.Bookmark
        i = i + 1
        Debug.Print objRs("ProductName")
    End If
    objRs.MoveNext
Loop

'Filter using the array of bookmarks.
objRs.Filter = vBkmkArray

objRs.MoveFirst
Do While Not objRs.EOF
    Debug.Print objRs("ProductName")
    objRs.MoveNext
Loop
'EndFilterBkmk