Z
Zanstemic
I'm running the following and having trouble getting the error handling
worked out. The casenumber is an indexed field with no duplicates. I'm
testing the error that would occur is a duplicate exists.
The error message is on .update and the window comes to the screen saying
that a duplicate casenumber exists as expected. I've tried a number of
different approaches but can't seem to get error handling to work. The
debugger comes up and takes me to the .update
Do While True
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenKeyset
.LockType = adLockPessimistic
.Open "Select * from Attendees; " '
.AddNew
!CPSAutoNumber = vbIncrementNumber
!CaseNumber = vbCaseNumber
![Date Received] = Date
.Update
End With
rst.Close
Set rst = Nothing
If Err.Number <> 0 Then
' insert failed, someone else must have grabbed the
' same number just before us
vbIncrementNumber = vbIncrementNumber + 1
Else
' okay it worked, this number now belongs to us
Exit Do
End If
Loop
worked out. The casenumber is an indexed field with no duplicates. I'm
testing the error that would occur is a duplicate exists.
The error message is on .update and the window comes to the screen saying
that a duplicate casenumber exists as expected. I've tried a number of
different approaches but can't seem to get error handling to work. The
debugger comes up and takes me to the .update
Do While True
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenKeyset
.LockType = adLockPessimistic
.Open "Select * from Attendees; " '
.AddNew
!CPSAutoNumber = vbIncrementNumber
!CaseNumber = vbCaseNumber
![Date Received] = Date
.Update
End With
rst.Close
Set rst = Nothing
If Err.Number <> 0 Then
' insert failed, someone else must have grabbed the
' same number just before us
vbIncrementNumber = vbIncrementNumber + 1
Else
' okay it worked, this number now belongs to us
Exit Do
End If
Loop