Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help needed. Network creates autonumber crash. why????

Status
Not open for further replies.

nadir66

IS-IT--Management
May 30, 2002
34
0
0
Hi
I built the autonumber using various help, it works on my pd, but when i place it into the BE, i get an error msg. Here is the module:
Public Function acbGetCounter() As Long
' Get a value from the counters table and
' increment it

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim intLocked As Integer
Dim intRetries As Integer
Dim lngTime As Long
Dim lngCnt As Long
' Set number of retries
Const conMaxRetries = 5
Const conMinDelay = 1
Const conMaxDelay = 10
On Error GoTo HandleErr
Set db = CurrentDb()
intLocked = False
Do While True
For intRetries = 0 To conMaxRetries
On Error Resume Next
Set rst = db.OpenRecordset("tblFlexAutoNum", _
dbOpenTable, dbDenyWrite + dbDenyRead)
If err = 0 Then
intLocked = True
Exit For
Else
lngTime = intRetries ^ 2 * _
Int((conMaxDelay - conMinDelay + 1) * Rnd + conMinDelay)
For lngCnt = 1 To lngTime
DoEvents
Next lngCnt
End If
Next intRetries
On Error GoTo HandleErr
If Not intLocked Then
If MsgBox("Could not get a counter: Try again?", _
vbQuestion + vbYesNo) = vbYes Then
intRetries = 0
Else
Exit Do
End If
Else
Exit Do
End If
Loop
If intLocked Then
acbGetCounter = rst![CounterValue]
rst.Edit
rst![CounterValue] = rst![CounterValue] + 1
rst.Update
rst.close
Else
acbGetCounter = -1
End If
Set rst = Nothing
Set db = Nothing
ExitHere:
Exit Function
HandleErr:
MsgBox err & ": " & err.Description, , "acbGetCounter"
Resume ExitHere
End Function
and the form code is:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim lngCounter As Long
If IsNull(Me!docket) Then
lngCounter = acbGetCounter()
' If no counter available
If lngCounter < 1 Then
' Cancel the Update event
Cancel = True
Else
' Write the key field
Me!docket = lngCounter
End If
End If
End Sub
Where am i wrong?
pls` help. application update today...:(
 
I would try setting a break point in the code and single step trough the module until the error occurs. If you don´t recognize a solution after doing that, at least you will be able to give a more specific error condition details to help others find the solution for you.
 
the error is that he loops and cannot add assign number.
It also said that due to a control it cannot save the record.
thx
 
If you were able to single step into the error message, please let me know which line of code caused the jump to &quot;HandleErr&quot;.

Also, it would help if I knew what you mean with &quot; it works on my pd, but when i place it into the BE...&quot;.

Is pd a personal desktop and BE a backend server?
 
Hi
Yes, Pd was a mistake, meant to be pc.yes be is backend.
Well, the error stopped on this line:

Set rst = db.OpenRecordset(&quot;tblFlexAutoNum&quot;, _
dbOpenTable, dbDenyWrite + dbDenyRead)
nadir
thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top