Results 1 to 4 of 4
  1. #1
    LoveLEE143 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    7

    Prevent duplicate records for calculated field

    I have a table for storing vehicles. The table contains the following fields:
    VehicleID
    Make


    Model
    Trim
    Build Date Begin
    Build Date End
    Vehicle Name - a concatenation of 'Make' 'Model' 'Trim' 'Build Date Begin' and 'Build Date End'

    The 'Vehicle ID' is the primary key, the rest of the fields can't be indexed with no duplicates. Is there a way of preventing one from saving a duplicate VehicleName on the table since it is a calculated field.

  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,722
    You should NOT do what you are trying to do with that PK set up.
    You will have partial dependencies by design.

    Use an autonumber PK for Access, if you want to output a concatenated field value of
    'Make' 'Model' 'Trim' 'Build Date Begin' and 'Build Date End' then go for it. But do NOT make that concatenation the primary key.

  3. #3
    LoveLEE143 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    7
    Quote Originally Posted by orange View Post
    You should NOT do what you are trying to do with that PK set up.
    You will have partial dependencies by design.

    Use an autonumber PK for Access, if you want to output a concatenated field value of
    'Make' 'Model' 'Trim' 'Build Date Begin' and 'Build Date End' then go for it. But do NOT make that concatenation the primary key.
    The vehicleID is the PK which is a auto number. But I need to prevent duplicate results of the concatenation.

  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,722
    Sorry for reading the PK as I did --???? For some reason, I got the message you were using the concatenation as PK. When I read it now, I see I misread/misunderstood/ (was thinking of something else)???


    You can make a multifield (compound) unique index.
    I would not save an individual field as Vehicle name.
    I would use an autonumber PK - if that's what you're using for VehicleID - OK.

    Then, you can make a compound unique index on the combination of fields you suggest. see this for more info

    Is it possible to have more than 1 vehicle with same
    'Make' and 'Model' and 'Trim' and 'Build Date Begin' and 'Build Date End'? If it is, then you know you will have physical duplicates so this would be a non-starter.

    If any of these fields could be NULL that would also make this a non-starter.
    Last edited by orange; 05-03-2013 at 11:50 AM. Reason: added link for unique composite index

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

Similar Threads

  1. Dcount prevent duplicate
    By ayamali in forum Programming
    Replies: 20
    Last Post: 04-16-2013, 09:31 PM
  2. Prevent duplicate dates
    By bishop0071 in forum Access
    Replies: 1
    Last Post: 01-09-2013, 09:04 PM
  3. Replies: 20
    Last Post: 09-12-2012, 06:52 PM
  4. Replies: 1
    Last Post: 01-04-2012, 01:39 PM
  5. Replies: 2
    Last Post: 02-12-2011, 09:54 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