Error Number of Duplicate Record Error (1 Viewer)

Ironis

Learning Member...
Local time
Today, 02:19
Joined
Oct 10, 2002
Messages
61
Hi,

I want to create my own error message on a duplicate record. The problem with the normal error message, is that the text is very long, and for users sometimes not understandable. So I want to create an error message, with 'normal' language, instead of the technical error message there is in Access.

Does anyone know the error number of this error message??
 

chenn

Registered User.
Local time
Today, 05:19
Joined
Apr 19, 2002
Messages
69
I do not know the error number off hand, however it is easy enough to find. On your error handling, put in something like:

msgbox err.number & err.description

Then force the error to occur. When it does, you will get the error number and text of what happened. Next in your error handler, add some code to trap it. For example:

Private sub TEST()
on error goto HandleErrors 'turn on your error handling

'This error handler should be placed at the end of the sub where the error may occur

HandleErrors:
If err.number = 2011 then 'your newly found number
msgbox "This is your new error text."
'put in what you want to do next here IE:
Textbox = ""
Textbox.setfocus
'etc....
Else
'here is your normal error handling for all other errors
msgbox err.description
end if

end sub
 

Ironis

Learning Member...
Local time
Today, 02:19
Joined
Oct 10, 2002
Messages
61
Tanks, the last part i knew, but thanks for explaining :) Now I will find the right number i guess!

Thanks again,

Ironis :cool:
 

Ironis

Learning Member...
Local time
Today, 02:19
Joined
Oct 10, 2002
Messages
61
Hmm, just tested it, got some errors, but the Duplicate Record seems to be no error, becouse it appears in its own form, without an error number.
The title of the box says "Microsoft Access", but still I'd like to have my own textbox there.
Does anyone know how to capture this event??
 

WayneRyan

AWF VIP
Local time
Today, 05:19
Joined
Nov 19, 2002
Messages
7,122
Ironis,

I think that you will have to test for it on your form.

Use the OnChange or AfterUpdate event on the field that
contains your primary key. Use the DLookUp function to check
if it is present in your data. If it is present, display a MsgBox
or clear the field or whatever.

Wayne

p.s. Still researching the swimmers.
 

vicsar

https://about.me/vicsar
Local time
Yesterday, 23:19
Joined
Jul 25, 2012
Messages
35
Did you try reading the Help section? It points to error 3022, I found and easy solution to this problem here:
msdn.microsoft.com/en-us/library/office/aa211376(v=office.11).aspx

(I know, old thread, yet it remains relevant. I had the same problem today).

The following example shows how you can replace a default error message with a custom error message. When Microsoft Access returns an error message indicating it has found a duplicate key (error code 3022), this event procedure displays a message that gives more application-specific information to users.
To try the example, add the following event procedure to a form that is based on a table with a unique employee ID number as the key for each record.



Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Const conDuplicateKey = 3022
    Dim strMsg As String

    If DataErr = conDuplicateKey Then
        Response = acDataErrContinue
        strMsg = "Each employee record must have a unique " _
            & "employee ID number. Please recheck your data."
        MsgBox strMsg
    End If
End Sub
 
Last edited:

princessdmb

Registered User.
Local time
Yesterday, 22:19
Joined
Sep 1, 2011
Messages
15
Hello,

I used the code:

Private Sub Form_Error(DataErr As Integer, Response As Integer) Const conDuplicateKey = 3022 Dim strMsg As String If DataErr = conDuplicateKey Then Response = acDataErrContinue strMsg = "Each employee record must have a unique " _ & "employee ID number. Please recheck your data." MsgBox strMsg End IfEnd Sub
and its working but i now get the "Macro Single Step" window. How can i stop it from pop-out? :banghead:

Your assistance is much appreciated
 

Users who are viewing this thread

Top Bottom