Results 1 to 2 of 2
  1. #1
    johnvog is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Dec 2014
    Posts
    1

    Ensuring no duplicates between 2 fields

    Hi all:

    I have a table named Contact Links which stores links between contacts.

    For example:


    John Smith and Mary Smith are Married so the Contact Links table stores this link.

    So, the table has the following fields which store the Primary Key from the Contacts Table.
    ContactsId
    Linked

    What I am wanting to do is have an index that will not allow a duplicate link no matter which way the contacts are stored.

    Entered as:
    ContactId -- John Smith's Id
    Linked -- Mary Smith's Id

    Do not allow:
    ContactID -- Mary Smith's Id
    Linked -- John Smith's Id

    Any suggestions would be greatly appreciated.

    John

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Would have to do a search of both fields for each ID. Code in BeforeUpdate event of both controls, something like:

    If (Not IsNull(DLookup("ContactID", "tablename", "CantactID=" & Me.ContactID)) OR Not IsNull(DLookup("Linked", "tablename", "Linked=" & Me.ContactID))) AND (Not IsNull(DLookup("ConctactID", "tablename", "ContactID=" & Me.Linked)) OR Not IsNull(DLookup("Linked", "tablename", "Linked=" & Me.Linked))) Then
    MsgBox "Contact link already exists."
    Cancel = True
    End If
    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.

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

Similar Threads

  1. Replies: 1
    Last Post: 12-23-2013, 03:19 PM
  2. Finding duplicates in two fields
    By skipnick in forum Access
    Replies: 6
    Last Post: 12-10-2013, 01:29 PM
  3. Allow ONLY duplicates in two fields
    By KWasley in forum Access
    Replies: 1
    Last Post: 04-17-2013, 09:04 AM
  4. Ensuring Proper Data Entry
    By skg in forum Forms
    Replies: 5
    Last Post: 01-27-2011, 10:12 PM
  5. Ensuring Everything Works...?
    By catat in forum Access
    Replies: 1
    Last Post: 03-31-2010, 01:44 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