A
ArielZusya
I've got this insert query running embedded in a VBA statement. The VBA
looks at a table and finds the largest number stored in the column BatchNum
and then adds 1 to it and stores that new number in the variable lngBatch.
It then runs the following SQL (note that the <lngBatch> as seen below is
just a placeholder... in the actual code the SQL statment is put into a
string and would be "... CaseNum," & lngBatch & vbCrLf & "FROM ..."):
INSERT INTO tblRef ( RefNum, BatchNum )
SELECT DISTINCT CaseNum, <lngBatch>
FROM tblMain;
This statement works just fine for my first insert (when tblRef is empty and
this is the first record being insterted) but when I go to the second time I
run this query on a new set of data with unique values, I get the following
error:
The changes you requested to the table were not successful because they
would create duplicate values in the index, primary key, or relationship.
Change the data in the field or fields that contain duplicate data, remove
the index, or redefine the index to permit duplicate entries and try again.
What am I doing wrong? Thanks for your help!
looks at a table and finds the largest number stored in the column BatchNum
and then adds 1 to it and stores that new number in the variable lngBatch.
It then runs the following SQL (note that the <lngBatch> as seen below is
just a placeholder... in the actual code the SQL statment is put into a
string and would be "... CaseNum," & lngBatch & vbCrLf & "FROM ..."):
INSERT INTO tblRef ( RefNum, BatchNum )
SELECT DISTINCT CaseNum, <lngBatch>
FROM tblMain;
This statement works just fine for my first insert (when tblRef is empty and
this is the first record being insterted) but when I go to the second time I
run this query on a new set of data with unique values, I get the following
error:
The changes you requested to the table were not successful because they
would create duplicate values in the index, primary key, or relationship.
Change the data in the field or fields that contain duplicate data, remove
the index, or redefine the index to permit duplicate entries and try again.
What am I doing wrong? Thanks for your help!