Avatar of SteveL13
SteveL13
Flag 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

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Gustav Brock

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ste5an

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

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?
Gustav Brock

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
SOLUTION
Dale Fye

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question