CodeItBetter Programming Another VB Programming Blog

Procedure which demonstrates the use of the .Seek method to locate a specific record in a recordset

Posted on July 4, 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
'Database - Procedure which demonstrates the use of the .Seek method to locate a specific record in a recordset
Sub ChangeName(intID As Integer, strNewName As String, strPath As String)
    '   intID: An integer that indicates the EmployeeID value to search for.
    '   strNewName: The new value for the EmplyeeName field.
    Dim dbs As Database, rst As Recordset
    Dim strPath As String
 
    Set dbs = OpenDatabase(strbPath)
    ' Open a table-type recordset on the Employees table.
    Set rst = dbs.OpenRecordset("Employees", dbOpenTable)
    With rst
        ' Define current index.
        .Index = "PrimaryKey"
        ' Seek record.
        .Seek "=", intID
        ' If EmployeeID is found.
        If Not .NoMatch Then
            .Edit
            ' Change Employee Name.
            !EmployeeName = strNewName
            .Update
        Else
            MsgBox "No record found for EmployeeID: " & intID
        End If
        .Close
    End With
End Sub
Filed under: Database Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.