Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Help preventing duplicate records

Help preventing duplicate records

Help preventing duplicate records

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.

RE: Help preventing duplicate records

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close