Results 1 to 12 of 12
  1. #1
    TinaH is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    12

    Unique Record

    Please Help!!

    I have a database that has several tables. The main table being COMPLAINT, where the CUSTOMER_ID is the Primary Key and is set to Auto Number.

    The COMPLAINT table has a one to many relationship to the COMPL_VIOL table



    COMPLAINT -----------< COMPL_VIOL

    I do not have a primary key defined in the COMPL_VIOL table because for every CUSTOMER_ID there could be multiple Violations (Violations against the customer is what is stored in the COMPL_VIOL table).

    However, in the COMPL_VIOL table I want to be able to state that for each CUSTOMER_ID only one PRIMARY_IND is allowed (PRIMARY_IND states what the main complaint from the customer is). Below is an example of the data I want to store in the COMPL_VIOL table.

    How can I make the PRIMARY_IND allowable only one time for each CUSTOMER_ID (sample data of what I want is attached).

    FYI - On the form I am hiding the CUSTOMER_ID (because the frmCOMPL_VIOL is a sub-form to COMPLAINT) and at this time the Business Owners only want the ACT to equal FLSA so this is set to a constant and the is visible but not enabled.
    Attached Files Attached Files

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The One -----------------------The many
    COMPLAINT ------------------> COMPL_VIOL
    CUSTOMER_ID (PK)-------------> CUSTOMERID_FK (Long Integer) (NOT autonumber!!!)

    The PK - autonunber is a Long Integer. The FK (foreign key) must also be a Long.
    The COMPLAINT PK field number is stored in the FK in the many table.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Would need code, probably in the BeforeUpdate event of control bound to PRIMARY_IND field. This code would check if Customer_ID already has a record with Y value in PRIMARY_IND field. Is PRIMARY_IND a text type field?


    Something like:

    If Not IsNull(DLookup("PRIMARY_IND", "COMPL_VIOL", "CUSTOMER_ID=" & Me.Customer_ID)) Then
    Cancel = True
    Me.PRIMARY_IND = Null
    MsgBox "This customer already has a record identified as primary."
    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.

  4. #4
    TinaH is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    12
    Yes, the CUSTOMER_ID FK is set to Long Integer and not number

  5. #5
    TinaH is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    12
    PRIMARY_IND is a True/False field

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Maybe:

    If Not IsNull(DLookup("PRIMARY_IND", "COMPL_VIOL", "CUSTOMER_ID=" & Me.Customer_ID & " AND PRIMARY_IND=True")) Then
    Cancel = True
    Me.PRIMARY_IND = False
    MsgBox "This customer already has a record identified as primary."
    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.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

    Boy, I really misread this one....... I hate it when i do that..... Sorry, shouldn't try and do three things at once.

  8. #8
    TinaH is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    12
    This did not work. The provided information will only allow me to enter one Violation per customer whether or not it is marked as a PRIMARY_IND

  9. #9
    TinaH is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    12

    Unique Record : Provided solution did not work

    I am attaching the Table and Form documentation from Access to show how both TABLES are being used. (I know the names are different then orginally stated, that was because I was at home researching the issue after work and did not have access to the database, but I did change the names is the scripts provided to what they are in the acutal database).
    Attached Files Attached Files

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Where did you put the code?

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  11. #11
    TinaH is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    12

    Unique Record - Database for Analysis

    I attempted to place the code on both the form COMPLAINT_VIOL and then when that did not work (would not allow me to enter a second field) I added the code to the field PRIMARY_VIOLATION_IND in the COMPLAIN_VIOL form which is a subform under the page tab named "Status of Complaince". On both attempts I placed the code in the Control BeforeUpdate.

    The database is attached and the only data in it is test data (a couple of rows)

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You have the VBA procedure but it is not associated with the control event. In the event BeforeUpdate property select [Event Procedure] then click the ellipsis (...) to open VBA editor at the procedure.

    Also, the DLookup syntax is wrong. Doesn't have the table/query argument. Don't need table/form name prefix. Also, I goofed, don't need line to set field to False. I got this to work:

    Code:
    Private Sub PRIMARY_VIOLATION_IND_BeforeUpdate(Cancel As Integer)
    If Me.PRIMARY_VIOLATION_IND = True Then
        If Not IsNull(DLookup("PRIMARY_VIOLATION_IND", "COMPLAINT_VIOL", "CUSTOMER_ID =" & Me.CUSTOMER_ID & " AND PRIMARY_VIOLATION_IND =True")) Then
            Cancel = True
            'Me!PRIMARY_VIOLATION_IND = False
            MsgBox "This customer already has a record identified as Primary Violation."
         End If
    End If
    End Sub
    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. Adding a unique identifier to each record
    By Jessica240 in forum Queries
    Replies: 28
    Last Post: 07-15-2014, 01:42 PM
  2. Next unique record ( Record Navigation )
    By ramindya in forum Access
    Replies: 5
    Last Post: 04-26-2012, 09:10 AM
  3. Creating unique record from record and field data
    By arthurpenske in forum Access
    Replies: 3
    Last Post: 08-24-2011, 06:11 PM
  4. Unique table per record?
    By Poepol in forum Access
    Replies: 8
    Last Post: 06-11-2011, 10:31 AM
  5. Make command buttons unique to a record
    By timmy in forum Forms
    Replies: 26
    Last Post: 03-09-2011, 09:51 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