Avoid duplicate entry in database through VB

100 pts.
Tags:
Data Deduplication
Delete duplicates
VB6
I have made a program in VB with Access as back end.  In the data base there are three fields which are unique id of a person.  I want to display "Already Exist" message box when i enter an already existing id. matching all three fields and not allow duplicate entry.

Software/Hardware used:
Visual basic with Access as back end[Br _extended="true" /> 

Can anyone tell me what codes should be used for this.

Answer Wiki

Thanks. We'll let you know when a new response is added.

The easiest way would be to let the database tell you there is a problem.

Create a primary key on the table which consists of those three columns.

Then put your insert command within a TRY/CATCH block. If the row already exists Access will throw an error message back to you which you can capture and display to the user.

Discuss This Question: 6  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    Hi Adwaith. You asked this question yesterday, and we would appreciate if you can continue the conversation in your previous question instead of creating a new one. If the answer provided did not help, please let us know, and try to provide more details, Thanks,
    68,820 pointsBadges:
    report
  • ItGuy400
    What if his primary key is not part of the insert ? What you should implement is a method to check if record exist based on some unique field prior to inserting the data if you are looking for uniqueness or just insert the record with a primary integer as an identity field which increments on each record insert.
    100 pointsBadges:
    report
  • Adwaith
    My problem still not solved. this is the code i gave. pls correct it. If Text1.Text = rp.Fields(0) And Text2.Text = rp.Fields(1) And Text3.Text = rp.Fields(2) Then t = MsgBox("Record exist", vbOKOnly)
    100 pointsBadges:
    report
  • carlosdl
    What type of object is "rp" ? how are you populating it ?
    68,820 pointsBadges:
    report
  • carlosdl
    Also, what version of Visual Basic are you using ?
    68,820 pointsBadges:
    report
  • Adwaith
    rp is assigned to the access database file as"rp=db.openrecordset("record") where db is the mdb file. VB6
    100 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following