How to check for primary key violation

SubMatrix

New member
Local time
Today, 17:59
Joined
Jan 10, 2009
Messages
8
I have a table with a primary key composed of two fields (Name and Class). I have a form that allows me to select a Name and then view all the classes they have attended. I can edit these classes or add new ones. In the Class field, if I type in a class that already exists for that name, I want to catch it in the BeforeUpdate(Cancel As Integer) sub. How can I do this?

I know that access will automatically generate a warning box but because of other message boxes and buttons that would exit the form (giving the user the impression that the record was saved when it was not) I need to be able to catch this in the BeforeUpdate section.
 
DCount will allow you to quickly see if there are are existing records with set criteria.
 
I have a table with a primary key composed of two fields (Name and Class). I have a form that allows me to select a Name and then view all the classes they have attended. I can edit these classes or add new ones. In the Class field, if I type in a class that already exists for that name, I want to catch it in the BeforeUpdate(Cancel As Integer) sub. How can I do this?
If you have a composite Primary Key comprised of the Name and Class fields, it should prevent you from entering the same combination of Name - Class.
 

Users who are viewing this thread

Back
Top Bottom