Checking for duplicate data & creating error msg if exist.

  • Thread starter Thread starter jdtivoli
  • Start date Start date
J

jdtivoli

I have a table with serial number fields which I have set
as indexed in order to prevent duplicate entries.

I have created a form for data entry. When I enter data
in one of the fields which are indexed in the table, the
data is not entered (which is good) but it doesn't any of
the data from the rest of the form either. That's fine
but it doesn't tell me that it did not enter the data.

I would like to know how to create an error message that
would be displayed as a "before update" on the form field
if there is duplicate data trying to be entered for that
field.

My thoughts are: Perhaps creating a find duplicates query
with an IIF statement for the error if the query results
are not Null. But don't know how to do this either.

Please Help.
 
There is a built in error message already for this. You wont receive this error message until you actually write the record to the table.This only happens when you go to another record (not another control), close the form, or save the record programatically. You should receive an error message about a duplicate in a primary key or index field ....etc. I had a problem where I was closing a form with command button and I wasn't receiving the message so I had to add the lin

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer7

before the DoCmd.Close command in the on click event of the button. My user's now receive the error message as expected
 
Back
Top