• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 18. Developing for a Multiuser E... > Testing a Record for Locking Status

Testing a Record for Locking Status

Often, you want to determine the locking status of a record before you attempt an operation with it. By setting the LockEdits property of the recordset to True and trying to modify the record, you can determine whether the current row is locked. The code looks like this:

Listing 18.6. Determining whether a record is locked before editing it.

Sub TestLocking()
   Dim db As Database
   Dim rst As Recordset
   Dim fLocked As Boolean

   Set db = CurrentDb
   Set rst = db.OpenRecordset("tblCustomers", dbOpenDynaset)
   fLocked = IsItLocked(rst)
   MsgBox fLocked

End Sub

Function IsItLocked(rstAny As Recordset) As Boolean
   On Error GoTo IsItLocked_Err
   IsItLocked = False

   With rstAny
      .LockEdits = True
      .Edit
      .MoveNext
      .MovePrevious
   End With
   Exit Function

IsItLocked_Err:
   If Err = 3260 Then
      IsItLocked = True
      Exit Function
   End If
End Function

					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint