The Basics > Understanding Bookmarks |
Both True DBList and the Microsoft Data Access Objects (DAO) library use bookmarks to identify records and navigate through the database. A bookmark is a variant that uniquely identifies a particular row in a database. As such, it is a generalization of the concept of row numbers.
Programmers who are accustomed to using row numbers to reference a record (as with dBASE databases) may need to adjust conceptually. In a relational database, the ordinal position of a record (that is, its row number) is irrelevant, since the total number of rows in the database or in a query result set is generally not available. After performing certain operations such as FindFirst (Recordset) or FindFirst (Recordset), the current record moves an unspecified number of rows forward and there is no efficient way to determine how many. To avoid time-consuming counting operations, most relational database systems have abandoned the practice of using row numbers and have adopted the bookmark approach.
Bookmarks are actually quite simple to use. The following are the basic rules to remember when using bookmarks in True DBList and in Visual Basic:
Each record, or row, has a unique bookmark.
You can move to a specific record by setting the Bookmark property of either the list or the Data control:
Example Title |
Copy Code
|
---|---|
TDBList1.Bookmark = SomeBookmark Data1.Recordset.Bookmark = SomeBookmark |
SomeBookmark is usually a bookmark you have obtained from the Data control, a clone, or a collection of bookmarks, such as True DBList's SelBookmarks collection. The Bookmark property of the list and the Data control will always contain the bookmark of the current record.
You navigate through the database by moving to the first or last record, or by moving relative (next or previous) to the current bookmark:
Example Title |
Copy Code
|
---|---|
Data1.Recordset.MoveFirst Data1.Recordset.MoveLast Data1.Recordset.MoveNext Data1.Recordset.MovePrevious |
In bound mode, you generally do not know the format, or semantics, of a bookmark, so do not attempt to read the details of a bookmark or construct a bookmark yourself. The only legitimate operations to perform on a bookmark are saving it to a variable, assigning it to an appropriate property or method, and comparing it to another bookmark to determine if the two are identical:
Example Title |
Copy Code
|
---|---|
' Saving a bookmark: Dim SomeBookmark as Variant SomeBookmark = Data1.Recordset.Bookmark ' Assigning a bookmark: Data1.Recordset.Bookmark = SomeBookmark ' To reliably compare bookmarks, you must first convert them ' into strings: Dim Bk1 As String, Bk2 As String Bk1 = SomeBookmark1 Bk2 = SomeBookmark2 If Bk1 = Bk2 Then ... End If |
Note that to reliably compare two bookmarks in Visual Basic, you must first convert them into strings as shown in the preceding example. For more information, see Application Mode Bookmarks.