Results 1 to 3 of 3
  1. #1
    Bryan Easter is offline Novice
    Windows 2K Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    5

    Preventing duplicate entries by multiple field check.

    I have a 2010 Access database that is mature. I am wanting to put a check in to stop duplicates at a certain point based on two criteria. The master table is tblConstraints in that table are two data points,MDR and Part Number, that need to be checked before a new record is created using a form.

    My intent is to use the beforeupdate function on the form to check both fields MDR and Part Number. If it is a duplicate it displays a message and then cancels it. If it is not a duplicate it saves the record and moves on.

    I was able to hack out this, which does prevent duplication of the MDR, but the same MDR couple have multiple part numbers so I need that extra check. Logic I am going for is if MDR and Part Number match it is a duplicate.

    Here's where I am.

    Private Sub MIR_BeforeUpdate(Cancel As Integer)
    If (Not IsNull(DLookup("[MDR]", _
    "tblConstraints", "[MDR] ='" _
    & Me!MDR & "'"))) Then


    MsgBox "MDR has already been entered in the database."
    Cancel = True
    Me!MDR.Undo
    End If

    End Sub

    Appreciate your help and time.

    Thanks.

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    In your table structure (design), you could go to Indexes, and create a unique compound index that is made up of the 2 fields involved.
    That's how you get the database software to prevent duplicates.

    If you currently have duplicates, Access will complain and tell you it can't create that unique index because your data violates your proposed index.

    Get rid of the current duplicates, then add the unique compound index to your table.

    Good luck

  3. #3
    Bryan Easter is offline Novice
    Windows 2K Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    5
    I'll have to research those. I've not played with them at all.

    Thanks for response.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 04-25-2012, 01:57 PM
  2. preventing duplicate records
    By Alliana Gray in forum Access
    Replies: 6
    Last Post: 08-11-2011, 01:18 PM
  3. Replies: 0
    Last Post: 03-09-2011, 02:59 PM
  4. How do I add multiple table entries using check boxes?
    By avarusbrightfyre in forum Access
    Replies: 3
    Last Post: 10-21-2010, 01:09 PM
  5. Replies: 1
    Last Post: 02-03-2010, 08:27 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums