• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 319
  • Last Modified:

How prevent duplicate records?

I have a form which contains a field that is a "combination" field made up of other fields on the form.  The form is bound to a table and the field is actually in a field in the table.

For example the form has "FirstName", "LastName","City"  Or like "John Smith Greendale".

Since it is not the primary key field I want to find a way to prevent the user from entering the record since it already exists and alert the user that that record already exists and not let them enter it again.

How can I do this?
0
SteveL13
Asked:
SteveL13
  • 2
  • 2
1 Solution
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
There are two ways:

1. In table design, but a unique index on the field(s).  An error will result when the user goes to save the record, which you can trap in the forms On Error event if you wish.

2. As soon as the user enters all the fields, or when they go to save the record, do a find on the existing records for all the fields and message or not as appropriate.

Jim.
0
 
SteveL13Author Commented:
How do I put a unique index on the fields?
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<How do I put a unique index on the fields? >>

1. open the table in design view.
2. click the indexes button on the toolbar.
3. On the first blank line, enter an index name (doesn't matter really what it is, but it must be unique).
4. List the first field off to the right.
5. If there are additional fields that make up the key for the index, list them in the lines following.  Don't not repeat the index name.
6. Click back on the row with the index name.
7. In the properties window below, indicate that duplicates are not allowed.

Jim.
0
 
SteveL13Author Commented:
Worked. Thanks.
0
 
SVongCommented:
Anyone please!
I am new in this Experts Exchange.
Please help How prevent duplicate records in SQL table using VB.Net 2012? (How to write the VB Code for that I meant).
Best regards,
SVong
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now