Publish date: 2003-03-26
Usage of bookmarks (VB)
'This sample demonstrates as to apply bookmarks,
'using IB Provider and Active Data Objects, for data access to an Interbase
Sub Sample13()
'connection
Dim con As New ADODB.Connection
'recordset
Dim rs As New ADODB.Recordset
'bookmark
Dim dblBookmark As Double
'other declares
Dim strMessage As String
'open connection
con.Open "file name=" & ThisWorkBook.Path & "\Db.ibp"
con.BeginTrans 'start transaction
rs.ActiveConnection = con 'set the active connection
'Creation of recordset with the bidirectional access
rs.Properties("Fetch Backwards") = True
rs.Properties("Scroll Backwards") = True
'use bookmarks
rs.Properties("Use Bookmarks") = True
'open recordset
rs.Open "select * from employee"
Do While True
' Show information about current employer and get
' user input.
strMessage = "Employer: " & rs!first_name & " " & _
rs!last_name & " " & _
rs!last_name & " " & _
"Enter command:" & vbCr & _
"[1 - next; 2 - previous;" & vbCr & _
"3 - set bookmark; 4 - go to bookmark; else exit]"
Select Case Val(InputBox(strMessage, "Enter the command number (Fetched " & _
rs.RecordCount & " records)"))
' Move forward or backward, trapping for BOF
' or EOF.
Case 1
rs.MoveNext
If rs.EOF Then rs.MoveLast
Case 2
rs.MovePrevious
If rs.BOF Then rs.MoveFirst
' Store the bookmark of the current record.
Case 3
varBookmark = rs.Bookmark
' Go to the record indicated by the stored
' bookmark.
Case 4
If IsEmpty(varBookmark) Then
MsgBox "No Bookmark set!"
Else
rs.Bookmark = varBookmark
End If
Case Else 'if user enter not in (1,4) then exit
Exit Do
End Select
Loop
'close all objects
rs.Close
con.CommitTrans
con.Close
End Sub