Results 1 to 4 of 4
  1. #1
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97

    Enforcing unique pairs of data using count function?

    I'm working on a database where I have entries of "Fiscal year" and "ProgramID". I want to enforce unique pairs, meaning that one shouldn't create multiple entries with the same fiscal year and programID.

    I've seen a few strange coding solutions out there, and I was wondering if the following would work.



    In the table, have a calculated field that is "FiscalYear & ProgramID", let's call it "UniquePairValidate"
    In the form, have an 'after update' event on both FiscalYear and ProgramID where it runs a COUNT query on the table for UniquePairValidate value. If the number is greater than 1, a duplicate exists.

    My questions

    1. Does this have to be a separate SQL query, or can it be done in the visual basic?
    2. Is there anything that would block this from working?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Can set a compound index in table and duplicate pairs will not be allowed.

    I would use domain aggregate function instead of recordset in VBA. Research DCount and DLookup.

    The calculated field is not necessary.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97
    Quote Originally Posted by June7 View Post
    Can set a compound index in table and duplicate pairs will not be allowed.

    I would use domain aggregate function instead of recordset in VBA. Research DCount and DLookup.

    The calculated field is not necessary.
    Thank you. "Compound index" was the term I needed to find the guides.
    Oh my gosh I'm so excited that this is going to work!

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

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

Similar Threads

  1. Unique and Count How best to Show Data
    By DaveT99 in forum Access
    Replies: 3
    Last Post: 04-16-2018, 08:11 AM
  2. Replies: 1
    Last Post: 03-06-2017, 06:48 AM
  3. Unique Pairs
    By wellsw in forum Access
    Replies: 2
    Last Post: 02-25-2015, 08:47 AM
  4. Unique queries - Unique Count
    By bigfish in forum Queries
    Replies: 7
    Last Post: 03-14-2012, 01:28 PM
  5. Enforcing Data Accuracy from FK
    By Minerva in forum Access
    Replies: 3
    Last Post: 02-21-2010, 04:01 PM

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