nadir66
IS-IT--Management
- May 30, 2002
- 34
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 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...