Question : How to prevent duplicate records from being entered in Db.

Hi Experts,

I have an Access Db and am using the INSERT command to insert records into the Db. My problem is how do I prevent a record from being entered if a duplicate record already exists within the Db. When I say duplicate I mean ColumnA and ColumnB match, the rest of the columns do not matter.

Answer : How to prevent duplicate records from being entered in Db.

Here is a try:
tble1:
FieldA      FieldB      otherField
10      20      old
11      21      old
12      22      old
20      20      old

tble2:
FieldA      FieldB      otherField
10      22      new
11      22      new
12      22      new
20      20      new
21      22      new


INSERT INTO tbl1 ( FieldA, FieldB, otherField )
SELECT tble2.FieldA, tble2.FieldB, tble2.otherField
FROM tble2
WHERE (((Not Exists (select FieldA,FieldB from tble1 where tble2.FieldA=tble1.FieldA and tble2.FieldB=tble1.FieldB))=True));

Result: tble1
FieldA      FieldB      otherField
10      20      old
10      22      new
11      21      old
11      22      new
12      22      old
20      20      old
21      22      new
Random Solutions  
 
programming4us programming4us