LockEdits Property Example

This example locks the Customer recordset in the Nwindex.mdb database before updating the value in the CUSTMR_ID field of the first record with the value in cell A1 on Sheet1. Locking the recordset ensures that no other user can modify the record while it’s being updated.

To create the Nwindex.mdb database, run the Microsoft Excel example for the CreateDatabase method.

Dim db As Database, rs As Recordset
Sheets("Sheet1").Cells(1, 1).Value = "ALWSO"
databasePath = Application.DefaultFilePath & "\NWINDEX.MDB"
Set db = DBEngine.Workspaces(0).OpenDatabase(databasePath)
Set rs = db.OpenRecordset("Customer")
valueToAdd = Sheets("Sheet1").Cells(1, 1).Value
With rs
    .LockEdits = True
    .Edit
    .Fields("CUSTMR_ID").Value = valueToAdd
    .Update
    MsgBox "The new value of CUSTMR_ID is " & _
        .Fields("CUSTMR_ID").Value
End With
rs.Close
db.Close