Repeating lock error unhandled

Halbert
01-09-2004, 02:49 PM
So -- I have a multi-user database application which uses an Access 2000 database. As a result, it has occasional errors when one user tries to access it at the same time as the next -- the lock error.

To fix that, I basically added error code that would retry a few number of times, since after a retry or two the original user was out of the database:

Public Function RegCheck() As Integer
On Error GoTo ErrControl
dim intErrCount as integer
...
'now get registration code from database
Start:

'Prepare to Populate Messages
Dim adoRec As New ADODB.Recordset
adoRec.Open "SELECT Code FROM Practice", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBloc, _
adOpenStatic, adLockOptimistic

'various manipulation code here

'now exit sub and have error procedure after
Exit Function

ErrControl:
'clean up first try
Set adoRec = Nothing
'first, just try it again 5 times
If intErrCount < 5 Then
intErrCount = intErrCount + 1
GoTo Start
End If

'if it makes it through 5 tries, then record the error.
ErrorRecord "RegCheck -- Module 2", Err.Number, Err.Description
End Function

This fixed my problem for a while just fine, but now -- if the database is locked at the first use, it goes to 'ErrControl' just like it should, and retries. But the SECOND time it is locked, it does *not* call the Error handler. It just puts up the run-time error screen and crashes out.

Anyone have any idea why it does not use the error handler the second time?

This happens both running at full speed, or going line by line: The first error uses the error handler, the second doesn't. This is without leaving the procedure at all.

vbdood
01-09-2004, 03:30 PM
After the first error your error handler is deamed 'active'. When the second error occurs VB needs to call an 'inactive' error handler and as it cannot find one the error is fatal.

I suggest not using an error handler for this. Instead, manually check .open for errors.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum