I have an error trap in my VB 5.0 code that doesn't work when an error
is coming from and MS Access db. These are errors that occur when
there is a primary key violation or a referential integrity violation.
I have done similar error trapping in the past and it worked fine.
The only difference in code is that I was using a data control in the
code that worked and now I'm working directly with the recordsets.
The following is the code sample. The error occus on rsPallet.Update:
On Error GoTo ErrHandler
rsPallet![StockNum] = txtPaperType.Text
rsPallet![LoadTicket] = txtLoadNum.Text
rsPallet![LinYds] = txtTotYards.Text
rsPallet![DateRec] = txtTruckDate.Text
rsPallet![RollCount] = txtNumRolls.Text
rsPallet![UserId] = gUserID
errorNumber = Err.Number
Select Case errorNumber
Case 3022 'primary key violation - load number is not unique for
the truck date given
message = "Load number " & txtLoadNum.Text & " has been used
on " & txtTruckDate.Text _
& ". Would you like me to assign a unique load
answer = MsgBox(message, vbYesNo, "Primary Key Violation")
If answer = vbNo Then
txtStockNum.SelStart = 0
txtStockNum.SelLength = Len(txtStockNum.Text)
loadNumber = rsLoadNum![UniqueNum]
txtStockNum.Text = loadNumber
rsLoadNum![UniqueNum] = (loadNumber + 1)
Case 3201 'invalid paper type, number given doesn't exit in
message = "The stock number " & txtStockNum.Text & " does not
exist." & _
" Please enter a valid stock number."
MsgBox message, vbExclamation, "Invalid Stock Number"
message = "The following error has occured: " & Err.Number &
", " & Err.Description
Has anyone else encounter this problem or know the solution?