CodeItBetter Programming Another VB Programming Blog

How to set and retrieve book marks in DAO.

Posted on July 5, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'Database - How to set and retrieve book marks in DAO.
Sub Bookmark()
    ' This procedure sets a bookmark on the current record,
    ' performs a seek operation, and returns to the original
    ' record when the seek fails.

    Dim dbs As Database, rst As Recordset
    Dim varOrigin As Variant
    Dim strPath As String
 
    'strPath is the path to the database
    Set dbs = OpenDatabase(strPath)
    ' Open table-type recordset.
    Set rst = dbs.OpenRecordset("Employees", dbOpenTable)
    With rst
        ' Set recordset index.
        .Index = "EmployeeName"
        MsgBox "Current Record: EmployeeName = " & !EmployeeName
        ' Return bookmark.
        varOrigin = .Bookmark
        ' Perform seek.
        .Seek "=", "Smith"
        ' Check for match.
        If .NoMatch Then
            Call MsgBox("Can't find employee ""Smith""", vbInformation, "There is no current record!")
            ' Set bookmark to original value to return to previous record.
            .Bookmark = varOrigin
        End If
        MsgBox "Current Record: EmployeeName = " & !EmployeeName
        .Close
    End With
    dbs.Close
    Set dbs = Nothing
End Sub
Filed under: Database Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.