Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Sep 2001
    Location
    New Zealand
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Notify if duplicate value entered (Access 97)

    Is there a way for Access to notify the user immediately that they have entered a duplicate value in the primary key field? Currently it only notifies the user when they move off the form. This means the user could waste a lot of time filling in the whole form, when they have already entered that data previously.
    Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Notify if duplicate value entered (Access 97)

    You could check for duplicates in the Before Update event of the text box bound to the primary key field on the form used for entering data (you can't check this at the table level).

    Private Sub txtPrimaryKey_BeforeUpdate(Cancel As Integer)
    If DCount("*", "tblData", "PrimaryKey=" & Chr(34) & Me.txtPrimaryKey & Chr(34)) > 0 Then
    MsgBox "This key value already occurs in the table.", vbExclamation
    Cancel = True
    End If
    End Sub

    Replace tblData, txtPrimaryKey and PrimaryKey with the appropriate names. I have assumed that the primarry key is a text field; if it is numeric, omit both occurrences of "& Chr(34)".

  3. #3
    2 Star Lounger
    Join Date
    Sep 2001
    Location
    New Zealand
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Notify if duplicate value entered (Access 97)

    Wow, thanks for fast reply, Hans.

Posting Permissions

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