grendell2099
Registered User.
- Local time
- Today, 05:07
- Joined
- Aug 9, 2006
- Messages
- 29
Hi all, I am having trouble trapping runtime error 3022 (duplicate value in a field with no duplicates).
For the table in question, when a user adds a record I use code to find the max index number and add one to it for the new record.
This works well. However, my current project has about 6 users who make a lot of entries during the day and sure enough yesterday two of them received the same index number. The second user received the runtime 3022 error.
I have tried to trap this thing, but I can only get my code to handle the first occurrance of the error. It may be over kill, but I would like a robust error handler that could deal with multiple 3022 error events. I bomb out on the me.requery line.
Seems like I am not successfully clearing the error after an occurance- any ideas would be greatly appreciated.
On Error GoTo ERR_HNDL
dim MyIndexTries as integer
Application.Echo false
Me.AllowAdditions = true
MyIndexTries = 1
DoCmd.GoToRecord , , acNewRec
TRY_AGAIN:
Me.INDEX = GetTableIndex("InspectionRecords", "INDEX") 'get the index number for a new record
Me.txtInspector = Environ("username")
Me.InspectDate = Format(Now, "mm/dd/yy")
Me.Requery
Me.cboPartNum.SetFocus
EXIT_SUB: 'CLEAR VARIABLES
Application.Echo True
Me.AllowAdditions = False
DoCmd.SetWarnings True
ErrorMessage = ""
MyIndexTries = 0
vStatusBar = SysCmd(acSysCmdClearStatus)
Exit Sub
ERR_HNDL:
If Err.Number = 3022 Then 'multiple users pulled the same index number
If MyIndexTries = 4 Then
DoCmd.GoToRecord , , acPrevious
MsgBox "There appears to be a problem generating an index number... contact the administrator"
Resume EXIT_SUB
End If
MyIndexTries = MyIndexTries + 1
Err.Clear
Pause (1)
GoTo TRY_AGAIN
End If
Resume EXIT_SUB
End Sub
For the table in question, when a user adds a record I use code to find the max index number and add one to it for the new record.
This works well. However, my current project has about 6 users who make a lot of entries during the day and sure enough yesterday two of them received the same index number. The second user received the runtime 3022 error.
I have tried to trap this thing, but I can only get my code to handle the first occurrance of the error. It may be over kill, but I would like a robust error handler that could deal with multiple 3022 error events. I bomb out on the me.requery line.
Seems like I am not successfully clearing the error after an occurance- any ideas would be greatly appreciated.
On Error GoTo ERR_HNDL
dim MyIndexTries as integer
Application.Echo false
Me.AllowAdditions = true
MyIndexTries = 1
DoCmd.GoToRecord , , acNewRec
TRY_AGAIN:
Me.INDEX = GetTableIndex("InspectionRecords", "INDEX") 'get the index number for a new record
Me.txtInspector = Environ("username")
Me.InspectDate = Format(Now, "mm/dd/yy")
Me.Requery
Me.cboPartNum.SetFocus
EXIT_SUB: 'CLEAR VARIABLES
Application.Echo True
Me.AllowAdditions = False
DoCmd.SetWarnings True
ErrorMessage = ""
MyIndexTries = 0
vStatusBar = SysCmd(acSysCmdClearStatus)
Exit Sub
ERR_HNDL:
If Err.Number = 3022 Then 'multiple users pulled the same index number
If MyIndexTries = 4 Then
DoCmd.GoToRecord , , acPrevious
MsgBox "There appears to be a problem generating an index number... contact the administrator"
Resume EXIT_SUB
End If
MyIndexTries = MyIndexTries + 1
Err.Clear
Pause (1)
GoTo TRY_AGAIN
End If
Resume EXIT_SUB
End Sub