Access 2010
Access 2003
Seminars
Tips & Tricks
Access Forum
Course Index Insider Circle
 
Tutorials   News   Tips   Forums   Help   Logon   Order  
 
     
 
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List

   

  Access   Excel   Word   Windows   FrontPage   Hardware   Misc

 

Microsoft Access Duplicate Values on Multiple Fields

Preventing Duplicate Values Across Multiple Fields with Two Indices

Q: How can I prevent the user from entering a record with duplicate values across MULTIPLE fields. For example, if I have CustomerID and PersonID in a table, the user could duplicate CustomerID or PersonID many times, but the combination of the TWO fields has to always be unique.

A: If you have a multi-field index and you set the fields individually to NO DUPLICATES then you won't be able to have a duplicate value in EITHER field.

In order to make it so that the COMBINATION of indexes is unique, then you can do that by setting both fields to be the PRIMARY KEY (with the little key button) but changing their index type to YES, DUPLICATE VALUES OK. Access will make sure that the combination of both records is unique or it will give you an error message.

If you want to be able to control what happens when the user violates the rules, then you need to do that with some VBA code. I would put it in the BeforeUpdate event of a form (before the record is actually saved) so that you can display a warning message and cancel the event.

Here is a sample database file that shows you the exact code: SAMPLE FILE - ZIP file, 13k, Access XP (2002) format

 

You may want to read these articles from the 599CD News:

 

 
Learn
 
Microsoft Access
Microsoft Excel
Microsoft Word
Microsoft Windows
Microsoft PowerPoint
Adobe Photoshop
Visual Basic
Active Server Pages
Online Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
WalkThru Tutorials
Free Upgrades
Insider Circle
Info
 
Latest News
New Releases
User Forums
Tips & Tricks
Search Our Site
Waiting List
Production Schedule
Help
 
Live Chat
Customer Support
Troubleshooting
FAQs
TechHelp
Consulting Services
About Us
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Live Chat
General Contact Info
Support Policy
Contact Form
Email Us
Mailing Address
Phone Number
Fax Number
Course Survey
Try Us
 
Free Lessons
Online Theater
Mailing List
Course Indexes:   Microsoft Access   Microsoft Excel   Microsoft Word   Microsoft PowerPoint   Visual Basic (VB)   Photoshop   Active Server Pages (ASP)  
Keyword Search Cloud:   What's This?   courses   microsoft access tutorials   vlookup   access   cartesian   excel   dlookup   vba   attendance   access 2007   sql   windows 7   combo box   pivot table   visual basic   test   iif   word   calendar   query   conditional formatting   pivot tables   photoshop   hlookup   access 101   excel 202   excel 2007   student attendance   update query   my account   word 2007   append query   quickbooks   queries   dsum   reports   powerpoint   if   microsoft access   dmax   mail merge   relationships   ms access   access 2010   vb   dcount   subforms   excel 2003   handbooks   html   599cd   combobox   if function   security   microsoft word   after update  
Copyright 2012 by 599CD.com, All Rights Reserved