Part III: More-Advanced Access Techniques
774
LISTING 21.5 (continued)
‘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
Again, a Select Case construct is used to handle the value returned by ErrorRoutine(). The
function is stopped only when the value of ErrorRoutine() is 4. Here’s the portion of
ErrorRoutine() for handling Error 3186:
Case 3186
‘ 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
Tip
The code in this listing is identical to Listing 21.3. Because of the similarities between Error 3260 and Error
3186, they may be handled with the same logic. In fact, you can combine the Case routines for Error 3260
and Error 3186 into a single statement:
Case 3260, 3186:
Error 3188: Could not update; currently locked by another session on this
machine
Error 3188 occurs when someone has more than one instance of a database open on the same
machine and tries to lock the same record in both sessions. Error handling is simple for this error;
it’s included in the global error handler — ErrorRoutine() — in the Chapter21.accdb
example database.