Home > How-To Library > Database
Procedure which demonstrates the use of the .Seek method to locate a specific record in a recordset
**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * **************************************************************** 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
If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.