Form Errors

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.
 
G

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top