Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help preventing duplicate records 1

Status
Not open for further replies.

VickyC

Technical User
Sep 25, 2010
206
CA
hello to all

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 assistance
Vicky C.
 
I assume tblB has an ID and 20 Fields, not an ID and 20 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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top