Bookmark Property Example

To test the following example with the Northwind sample database, you need to add a command button named cmdFindContactName to the Suppliers form, and then add the following code to the button's Click event. When the button is clicked, the user is asked to enter a portion of the contact name to find. If the name is found, the form's Bookmark property is set to the Recordset object's ADO Bookmark property, which moves the form's current record to the found name.

Private Sub cmdFindContactName_Click()
    Dim rst As adodb.Recordset, strCriteria As String
    strCriteria = "[ContactName] Like '*" & InputBox("Enter the " _
        & "first few letters of the name to find") & "*'"

    Set rst = Me.RecordsetClone
    rst.FindFirst strCriteria
    If rst.NoMatch Then
        MsgBox "No entry found"
    Else
        Me.Bookmark = rst.Bookmark
    End If
End Sub