Form Errors

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got this code that traps various form level errors:

Private Sub Form_Error(DataErr As Integer, Response As Integer)

Select Case DataErr
Case 3022
Response = acDataErrContinue 'Don't display the Access default
error message
MsgBox "You have entered a duplicate Location code!" & vbCrLf & _
"Hit ESC to exit and start over", vbCritical, "Key Violation"
txtLoc.SetFocus
Case Else
MsgBox "Error #: " & DataErr
Response = acDataErrDisplay 'Display the Access default error message
End Select

End Sub

It all works fine, but how can I get the CASE ELSE portion to display the
default error message along with the Error Number in the MsgBox. Right now,
it displays the error number in one box, and the error message in another.
 
Try

Private Sub Form_Error(DataErr As Integer, Response As Integer)

Select Case DataErr
Case 3022
Response = acDataErrContinue 'Don't display the Access default
error message
MsgBox "You have entered a duplicate Location code!" & vbCrLf & _
"Hit ESC to exit and start over", vbCritical, "Key Violation"
txtLoc.SetFocus
Case Else
MsgBox "Error #: " & DataErr & " - " & Error(DataErr)
Response = acDataErrContinue 'Don't display the Access default
End Select

End Sub
 
That did the trick - thank you!

Ofer Cohen said:
Try

Private Sub Form_Error(DataErr As Integer, Response As Integer)

Select Case DataErr
Case 3022
Response = acDataErrContinue 'Don't display the Access default
error message
MsgBox "You have entered a duplicate Location code!" & vbCrLf & _
"Hit ESC to exit and start over", vbCritical, "Key Violation"
txtLoc.SetFocus
Case Else
MsgBox "Error #: " & DataErr & " - " & Error(DataErr)
Response = acDataErrContinue 'Don't display the Access default
End Select

End Sub
 
Back
Top