Results 1 to 9 of 9
  1. #1
    Clarkeyboy is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2018
    Posts
    11

    Duplicate entries over multiple fileds


    Hi, I am creating a database system for a school project and I'm fairly new to Access:
    I am creating a dentist booking system for a fictional dentist company...
    I have created a form to add new appointments but I do not want to double book times etc...
    I have 4 dentists with 15 minute appointment slots available. How would I prevent double booking the same dentist at the same time?
    Any help is much appreciated.

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,127
    One way of doing it is to have a composite primary key using both dentist name and appointment date/times
    That will prevent the combination of values being repeated
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #3
    Clarkeyboy is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2018
    Posts
    11
    Thanks, If I were to do that, would the composite primary key prevent all duplicate values?
    For example, If dentist 1 had an appointment at 10:00 on 22nd May, would it allow me to have an appointment at the exact same time with dentist 2?
    Or would the composite key only prevent duplicates if every field was the same?

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,127
    Quote Originally Posted by Clarkeyboy View Post
    Thanks, If I were to do that, would the composite primary key prevent all duplicate values?
    For example, If dentist 1 had an appointment at 10:00 on 22nd May, would it allow me to have an appointment at the exact same time with dentist 2?
    Or would the composite key only prevent duplicates if every field was the same?
    Primary keys prevent duplicates
    Having a composite PK would only prevent duplicates of both fields.
    So you can still make appointments for other dentists at that time or the same dentist at any other time
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    Clarkeyboy is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2018
    Posts
    11
    Okay, but when i set the index to "Yes(No duplicates)" I receive the following:
    The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. (Error 3022)

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,127
    Quote Originally Posted by Clarkeyboy View Post
    Okay, but when i set the index to "Yes(No duplicates)" I receive the following:
    The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. (Error 3022)
    That's because you already have duplicates so you need to identify and remove those
    One way to do so is by using the wizard to create a duplicates query.

    But if you select both fields and then click Primary Key in the ribbon, it should automatically set both fields to 'Yes, no duplicates'
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    The two fields do not have to be the key, just set them as a compound index. Autonumber field can still be primary key.
    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.

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,127
    Quote Originally Posted by June7 View Post
    The two fields do not have to be the key, just set them as a compound index. Autonumber field can still be primary key.
    True but the OP still needs to remove the existing duplicates
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  9. #9
    Clarkeyboy is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2018
    Posts
    11
    Thank you both!!! I ended up trying that compound unique index (Was quite easy in the end)
    Much appreciated

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

Similar Threads

  1. Replies: 3
    Last Post: 05-05-2017, 07:41 AM
  2. Replies: 1
    Last Post: 12-07-2015, 10:53 AM
  3. Replies: 8
    Last Post: 09-16-2013, 01:12 PM
  4. Replies: 2
    Last Post: 02-28-2013, 10:06 AM
  5. Duplicate Entries
    By brownk in forum Reports
    Replies: 3
    Last Post: 09-11-2012, 12:56 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