Results 1 to 3 of 3
  1. #1
    Rennie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    2

    Unique value in a subform

    I have a database with businesses in one table and contacts (people) in another table linked together. When entering a new record in the form you enter the details of the business then in a subform enter the details of the contacts for that business.



    One of the contact fields is called prime contact, which is meant to be used to indicate this is the main contact for the business. There is only meant to be one of these per business.

    My question is how do I put a setting in the subform that only allows one record to be selected as prime contact (yes/no field) or show up some sort of warning box if people try to add a second prime contact for the same business?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,600
    One way would be VBA code in the BeforeUpdate event of the PrimeContact testbox. This code would query the table for record associated with this buisness already checked as prime. This could use DLookup, something like:
    If Me.textboxPrime.NewValue = Yes AND Not IsNull(DLookup("ContactID","Contacts","Prime=Yes AND BusinessID=" & Me.textboxID)) Then
    MsgBox "A contact is already designated as prime."
    Cancel = True
    End If

    Another way might be to have a field in Businesses table for the PrimeContact record ID (no Yes/No field in Contacts).
    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
    Rennie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    2
    Thanks very much for that, I took your idea of having the link in the business table and created a filed in the business table that listed a single contact ID as the prime contact, then I just checked against this when changing prime contacts. Thanks again for the inspiration.

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

Similar Threads

  1. Unique attachments
    By twalishuka in forum Programming
    Replies: 1
    Last Post: 02-28-2011, 09:28 AM
  2. Unique ID problem
    By Remster in forum Access
    Replies: 10
    Last Post: 10-12-2010, 01:48 PM
  3. composite unique key
    By shital in forum Access
    Replies: 1
    Last Post: 07-09-2010, 08:07 AM
  4. how to set a unique ID
    By archie in forum Access
    Replies: 1
    Last Post: 09-08-2009, 04:28 AM
  5. Unique Puzzle
    By Christina G in forum Database Design
    Replies: 0
    Last Post: 03-14-2009, 06:37 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