Help preventing duplicate records

Help preventing duplicate records

Help preventing duplicate records

I am using code behind a command button that attempts to save a record in one table (tblA) to another (tblB).

tblB has an autonumber ID and 20 records (I1, I2, ...I20) that can hold integer values. These 20 integer records are from tblA.

Here's my problem. I don't want to allow the save to tblB if the set of 20 integer values already exists in tblB. I've tried setting a pk on the combination of all 20 fields, but this would fail because some of the fields may be null.

I could actually get this to work properly using a very large DCount expression (in a BeforeUpdate event) whose 'WHERE' part compares all 20 fields in both tables, then stops the save where DCount > 0. But, this seems excessively complicated.

Is there an easy way to ensure that records (that may include null fields) are not duplicated? I feel like I'm missing something obvious.

thanks for any assistanceVicky C.

RE: Help preventing duplicate records

I would build a query and store it, that compares all the fields. You would have to wrap the values in a NZ in the query. It is not going to be any shorter than the Dcount, but it would be a lot easier to build and maintain using a query, and should be more efficient. Then you can use a very simple dcount on that query. If it returns 1 record you have a match.