How VB Can Determine If Table Is Locked By Other ProcessesID: Q106535
|
This article describes how to detect if a database table has any records locked by other users or processes. If you open the table with the options to deny read and write access, a trappable error will indicate that other users or processes are using the table. This information is useful for managing tables in a multiuser or network system.
Sub Command1_Click ()
Dim db As database
Set db = OpenDatabase("biblio.mdb")
Dim ds As dynaset
Set ds = db.CreateDynaset("authors")
ds.Edit ' Locks the first record in the dynaset.
MsgBox "First record in dynaset is locked. Press OK to unlock."
command1.Caption = "record now unlocked"
End Sub
Sub Command1_Click ()
Dim db As database
Set db = OpenDatabase("biblio.mdb")
Dim tb As table
' See if table has locks by opening and denying others Read/Write:
On Error Resume Next
Set tb = db.OpenTable("authors", 3) ' 3 = Deny Read & Write (2+1)
If Err = 0 Then
command1.Caption = "not locked"
Else
command1.Caption = "locked due to err=" & err
End If
tb.Close
' If no error here you could reopen table without denying access.
End Sub
First record in dynaset is now locked. Press OK to unlock.
Additional query words: 3.00 row locking multiuser
Keywords :
Version :
Platform :
Issue type :
Last Reviewed: June 18, 1999