Avatar of SteveL13
SteveL13Flag for United States of America

asked on 

Prevent duplicate record from being written to a table

I have a datasheet form that has 5 fields.  If the user double clicks the record selector the record is written to a separate table.  But if the user d/c again and that record has already been written to the table I don't want to allow it if it is an exact duplicate (all 5 fields).  How can I prevent this from being allowed?
Microsoft Access

Avatar of undefined
Last Comment
Dale Fye
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of ste5an
ste5an
Flag of Germany image

hmm, create an unique index over one of the (natural) candidate keys, instead of using the surrogate primary key over as only unique index.
Avatar of SteveL13
SteveL13
Flag of United States of America image

ASKER

Gustav, I think I did what you suggested.  I went to the design of the table, indexes, and added all 5 fields and made them Unique = Yes.  It worked.  Did I do exactly what you suggested?

Also, is there a way to let the user know the record couldn't be added because it already exists?
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Yes, that's it.
But to play nicely, you'll have catch the error when trying to insert the record and, if so, pop a normal messagebox to inform the user politely.
SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo