Home

Updating a Record

 

Updating a Record

To update a record in the Microsoft Access Object Library, first locate the record. After identifying the record, call the Edit() method of the Recordset class. Here is an example:

Private Sub cmdUpdate_Click()
On Error GoTo cmdUpdate_Error

    Dim curDatabase As Object
    Dim rstEmployees As Object
    Dim fldEmployee As Object
    
    Set curDatabase = CurrentDb
    Set rstEmployees = curDatabase.OpenRecordset("Employees")
    
    With rstEmployees
        Do Until .EOF
            For Each fldEmployee In .Fields
                If fldEmployee.Name = "EmployeeID" Then
                    If fldEmployee.Value = CInt(txtEmployeeID) Then
                        ' The record to be edited has been located
                        .Edit
                        .Fields("DateHired").Value = txtDateHired
                        .Fields("FirstName").Value = txtFirstName
                        .Fields("LastName").Value = txtLastName
                        .Fields("HourlySalary").Value = txtHourlySalary
                        .Update
                        Exit For
                    End If
                End If
            Next
            .MoveNext
        Loop
    End With
   
    Exit Sub

cmdUpdate_Error:
    MsgBox "There was a problem when editing the record."
End Sub

 

 
 
     
 

Home Copyright © 2009-2016, FunctionX, Inc.