100 pts.
 Avoid duplicate entry in database through VB
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.



Software/Hardware used:
Visual Basic with Access
ASKED: Jan 13, 2010  4:27 PM GMT
UPDATED: January 15, 2010  8:55:44 AM GMT
63,630 pts.

Answer Wiki:
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.
Last Wiki Answer Submitted:  Jan 13, 2010  8:52 PM (GMT)  by  Mrdenny   63,630 pts.
Latest Answer Wiki Contributors:  Carlosdl   60,245 pts.
To see other answers submitted to the Answer Wiki View Answer History.
Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _




 

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,

 60,245 pts.

 

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 pts.

 

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 pts.

 

What type of object is “rp” ?
how are you populating it ?

 60,245 pts.

 

Also, what version of Visual Basic are you using ?

 60,245 pts.

 

rp is assigned to the access database file as”rp=db.openrecordset(”record”) where db is the mdb file.
VB6

 100 pts.