Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Tips & Tricks

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

   
 

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

 


By Richard Rost   Richard Rost on LinkedIn Email Richard Rost
Click here to sign up for more FREE tips

 

 

 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2024 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 3/28/2024 9:51:13 AM. PLT: 0s