• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 132
  • Last Modified:

Pessimistic Locking

I have a database named School and a table named module.  When I enter the edit mode I am able to change information.  If I am in edit mode and someone else tries to manipulate the record I am working on, I want an error to occur when the second user hits the Save button.  I am using SQL for all my searches, adds, updates, and deletes.  Can you give me the code that will accomplish this procedure?
0
paulca
Asked:
paulca
  • 3
1 Solution
 
clifABBCommented:
The following will open the database for exclusive use:
Set dbData = OpenDatabase("School.mdb", True)

The following will open the table with pessimistic locking:
Set rsTable = dbData.OpenRecordset("module", dbOpenDynaset,,dbPessimistic)
0
 
paulcaAuthor Commented:
I was also looking for the errot trapping code.  I'll add another 5 points since I was not specific with that point.
0
 
clifABBCommented:
Your error handler might look like this:

On Error Goto HandleError
'
'Process code here
'
Exit Sub

HandleError:
If Err.Number = 3186 Then
  'The user attempted to update a page that contains a read lock placed by another user.
  nRes = MsgBox("Another user has this record locked.  Try again?", vbYesNo + vbQuestion, "Write Error")
  If nRes = vbYes Then
    Resume
  Else
    Exit Sub
  End If
Else
  'Handle other errors
End If
0
 
clifABBCommented:
Modify the line to read:
If Err.Number = 3186 Or Err.Number = 3260 Then
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now