Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 14th, 2007, 11:07 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?

 
Old February 16th, 2007, 08:42 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I think you need to add the Error.Number and Error.Description to the strMessage (It may be Err, or ErrorObject).

Then, you will probably want to put this line in your code where you want to intercept errors:

On Error Resume Next

If DataErr is an Integer, then Case 3022 should work to catch it, unless you need to specify:

Select Case DataErr.Number

or

Select Case Error.Number

I have used Err.Number

Did that help?

mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
error messages strt_prg Struts 1 November 13th, 2006 07:05 AM
error messages timbal25 Classic ASP Databases 0 August 1st, 2006 02:56 PM
Error messages ldoodle Access ASP 12 June 6th, 2005 01:05 PM
Access 2000 pop-up messages? cjdphlx Access VBA 1 May 11th, 2005 02:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.