Solved

Pessimistic Locking

Posted on 1998-06-16
4
128 Views
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?
0
Comment
Question by:paulca
[X]
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
4 Comments
 
LVL 6

Accepted Solution

by:
clifABB earned 10 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)
0
 

Author Comment

by:paulca
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.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1463419
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
 
LVL 6

Expert Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

688 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