Solved

How prevent duplicate records?

Posted on 2014-02-17
5
302 Views
Last Modified: 2015-07-30
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
Comment
Question by:SteveL13
  • 2
  • 2
5 Comments
 
LVL 57
ID: 39865419
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
 

Author Comment

by:SteveL13
ID: 39865441
How do I put a unique index on the fields?
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 39865468
<<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
 

Author Closing Comment

by:SteveL13
ID: 39865605
Worked. Thanks.
0
 

Expert Comment

by:SVong
ID: 40906316
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
update all email addresses SQL 1 24
backup programme - VBA 3 24
Open VBA code while form is open and running. 4 27
My SQL as Backend for Access 3 17
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question