Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Feb 2006
    Posts
    10
    Thanks
    0
    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.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    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
    End Select
    End Sub

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •