Results 1 to 4 of 4
  1. #1
    Aaron5714 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    48

    How to check for duplicate values in a subform

    I am working on a database to manage contract documents. Here is a sample version: http://dl.dropbox.com/u/65832352/Exa...Database.accdb

    If you click the "New Contract" button on the main form, the contract detail form will load. This form has two subforms for adding locations and accounts to the contract. I am trying to figure out the best way to prevent users from adding the same location or account more than once on each subform. Ideally I would like to have a proceedure run when the "Save and Close" button is clicked that would check for this condition and alert the user if it found duplicate accounts or locations on the subforms.

    I am not quite sure how to do this. I was thinking it might be possible with DLookup or DCount statements, or maybe by reading the tables that the subforms are bound to, for example "tblContractAccounts", and trying to identify if there are records with the same combination of "ContractID" and "AccountID" values.

    If anyone could point me in the right direction it would be much appreciated.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    Research " compound unique index" or "multi field unique index".

    You can do what you want by setting a unique index on the fields involved.

    See Bob Larson's sample at http://www.btabdevelopment.com/ts/mfi

  3. #3
    Aaron5714 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    48
    Thanks orange! I didn't that you could create an index with multiple fields. That solved my problem.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847

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

Similar Threads

  1. check duplicate records within same table
    By cthorn112 in forum Queries
    Replies: 0
    Last Post: 06-19-2012, 12:23 PM
  2. check text box after update for duplicate
    By smahdih in forum Access
    Replies: 1
    Last Post: 11-05-2011, 05:35 PM
  3. check for duplicate First and Last names?
    By newtoAccess in forum Access
    Replies: 3
    Last Post: 03-19-2011, 04:05 PM
  4. Replies: 0
    Last Post: 03-09-2011, 02:59 PM
  5. Duplicate Check code with Run-Time error '3079'
    By viper in forum Programming
    Replies: 5
    Last Post: 10-18-2010, 10:12 AM

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