change access error messages
Hi,
I found the next thing in a book, but it doesn't seem to work. Does anyone knows why?
The code is made to intercept the jet error messages and change them to a message I create myself. This makes an error more clear for the database user. The code I found and I changed to my own needs is:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Dim strMessage As String
'Personalize Jet error message
Select Case DataErr
Case 3022
strMessage = "Het ingevoerde artikelnummer bestaat al." & vbCrLf & "Le numéro d'article exist déja. Veuillez corriger."
Case Else
strMessage = "De volgende fout heeft zich voorgedaan:" & vbCrLf & "L'erreur suivante c'est produite:" & Err.Description & " (" & Err.Number & ")"
End Select
'show personalized message
If DataErr <> 0 Then MsgBox strMessage, vbExclamation
'configure response
Response = acDataErrContinue
End Sub
The dim strmessage as string I added myself because the code was not working. With this extra line the code doesn't work on the case 3022 (primary key violation) and on all other cases the message box appears, but only with the text I added in the strmessage (the error description and error number are not shown).
When it is a primary key violation I just get a message that tells me: 'You can't go to specific record.'
Adding a new record is made with an action button, NEVER by moving to the next record with the tabulator key. Can this be responsible for the code not working the way it should?
|