HandsOn Marking Records with a Bookmark

1. In the Visual Basic Editor window, choose Insert | Module.

2. In the module's Code window, type the TestBookmark procedure shown below.

3. Choose Run | Run Sub/UserForm to execute the procedure.

Sub TestBookmark()

Dim rst As ADODB.Recordset Dim varMyBkmrk As Variant

Set rst = New ADODB.Recordset rst.Open "Employees", _

CurrentProject.Connection, adOpenKeyset

If Not rst.Supports(adBookmark) Then

MsgBox "This recordset does not support bookmarks!" Exit Sub End If varMyBkmrk = rst.Bookmark Debug.Print rst.Fields(1).Value

' Move to the 7th row rst.AbsolutePosition = 7 Debug.Print rst.Fields(1).Value

' move back to the first row using bookmark rst.Bookmark = varMyBkmrk

Part II

Debug.Print rst.Fields(1).Value rst.Close Set rst = Nothing End Sub

Notice that the procedure above uses the AbsolutePosition property of the Recordset object. The absolute position isn't the same as the record number. This property can change if a record with a lower number is deleted.

0 0

Post a comment