Pessimistic Locking

Posted on 1998-06-16
Medium Priority
Last Modified: 2010-05-03
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?
Question by:paulca
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Accepted Solution

clifABB earned 30 total points
ID: 1463417
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)

Author Comment

ID: 1463418
I was also looking for the errot trapping code.  I'll add another 5 points since I was not specific with that point.

Expert Comment

ID: 1463419
Your error handler might look like this:

On Error Goto HandleError
'Process code here
Exit Sub

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
    Exit Sub
  End If
  'Handle other errors
End If

Expert Comment

ID: 1463420
Modify the line to read:
If Err.Number = 3186 Or Err.Number = 3260 Then

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question