LockEdits Property Example (MDB)
The following example opens a dynaset-type Recordset object and sets its LockEdits property to False (0). This enables optimistic locking so other users can change the database records at any time. Microsoft Access triggers a trappable error if the data changes before you use the Update method.
Sub ShowLockStatus()
Dim dbs As Database, rst As Recordset
' Return reference to current database.
Set dbs = CurrentDb
' Open dynaset-type Recordset object.
Set rst = dbs.OpenRecordset("Customers", dbOpenDynaset)
rst.LockEdits = False
On Error Goto ErrorLockEdits
' Enable editing.
rst.Edit
. ' Change records.
.
.
rst.Update ' Try to post changes.
ExitLockEdits:
rst.Close
Set dbs = Nothing
Exit Sub
ErrorLockEdits:
If Err.Number = 3197 Then
MsgBox "Data changed by another user."
Resume Next
Else
MsgBox "Some other error."
Resume ExitLockEdits
End If
End Sub