Results 1 to 2 of 2
2006-02-01, 21:07 #1
- Join Date
- Feb 2006
- Thanked 0 Times in 0 Posts
replaceing duplicate key field msg(MS Access 2003)
I would like to display an alternate (custom) message instead of the default message that MS Access generates when a person tries to enter a duplicate value in a Key field that is set up as Indexed (No Duplicates). Is there a minimally painful way to do this.
2006-02-01, 21:17 #2
- Join Date
- Mar 2002
- Thanked 29 Times in 29 Posts
Re: replaceing duplicate keep field message (MS Access 2003)
You need a bit of VBA code for this:
<UL><LI>Open the form in design mode.
<LI>Activate the Event tab of the Properties window.
<LI>Click in the On Error event.
<LI>Select [Event Procedure] from the dropdown list in this event.
<LI>Click the ... button to the right of the dropdown arrow.
<LI>You'll be taken to the Visual Basic Editor. Complete the code so that it looks like this (you can copy/paste from this reply):
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 3022 ' Duplicate key
' Modified error message
MsgBox "This would result in a conflict.", vbExclamation
' Suppress built-in message
Response = acDataErrContinue
Case Else ' Other errors
' Let Access display the standard message
Response = acDataErrDisplay
<LI>Switch back to Access and save the form.[/list]You can add other cases later on, to display custom error messages for other form-level errors.