Testing a Record for Locking Status

You may want to test a record to check if it’s locked without actually locking its page or pages. In Microsoft Jet 3.0 and 3.5, Recordset objects have an EditMode property. You can use this property in conjunction with the LockEdits property to determine if the current record is locked.

The following procedure tests whether the current record in a given Recordset is on a locked page:

Function IsRecordLocked(rst As Recordset) As Boolean
	IsRecordLocked = False
  
	If rst.LockEdits Then
		If rst.EditMode = dbEditInProgress Then
			IsRecordLocked = True
		End If
	End If
End Function

If you’re using Microsoft Jet 2.0, the EditMode property is not available. In this situation, you can accomplish the same test by setting the LockEdits property of the Recordset to True, using the Edit method to attempt a lock, and then trapping error message 3260 (or other relevant error messages) if they occur.

The following procedure tests whether the current record in a given Recordset is on a locked page without using the EditMode property:

Function IsRecordLocked2(rst As Recordset) As Boolean
	IsRecordLocked2 = False
  
	On Error GoTo Err_IsRecordLocked2
	With rst
		.LockEdits = True
		' Attempt the lock.
		.Edit
	End With
	' Return to the calling routine to edit the record.
Exit Function
  
Err_IsRecordLocked2:
	IsRecordLocked2 = True
	Exit Function
End Function