Microsoft Access 2010 Bible

(Rick Simeone) #1

Part III: More-Advanced Access Techniques


772


LISTING 21.4 (continued)
HandleError:
‘Update Retry Count:
lngTryCount = lngTryCount + 1
‘Call ErrorRoutine, passing
‘in the number of retries:
Select Case ErrorRoutine(lngTryCount)
Case 3
‘Try again at the same statement
‘that caused the error:
Resume
Case 4
MsgBox “Edit Canceled”
GoTo ExitHere
End Select
End Function

The portion of code from ErrorRoutine() that handles this error is shown in the following list-
ing. This code fragment contains an empty loop that provides a little bit of time for the lock to be
released. As long as the value of TryCount is less than 10 , the loop will be executed and the value
of ErrorRoutine() is set to 3. If ErrorRoutine() has been called ten or more times,
ErrorRoutine() is set to 4 , which ends the attempt to rectify the situation.

Case 3260
‘ Record is locked on another machine
If TryCount < 10 Then
For lngCounter = 0 To 15000
‘Empty loop for short delay...
DoEvents
Next lngCounter
ErrorRoutine = 3
Else
ParseError Err, Error
ErrorRoutine = 4
End If

Error 3186: Couldn’t save; currently locked by user x on machine y
Sound familiar? This error is much like Error 3260 (see the preceding section), except for one dif-
ference: Error 3260 states that the record couldn’t be updated; Error 3186 states that the record
couldn’t be saved. You can’t update a record that you can’t get a lock on for editing (pessimistic
locking). But if you can get a lock on a record but not save it, it must be an optimistic record-
locking error.

As an example, let’s say two users are trying to edit the same record, but one is using pessimistic
locking and the other is using optimistic locking. Both can pull the record into memory for updating
Free download pdf