I am attempting to move all the data from one table that might be corrupt to another table.
Here is the query I am using:
INSERT INTO Transactions2 ( ID1,TDate, BoxID, OldQty, Adjustments, AdjRemove, NewQty, Initials, Aisle, Sect, Box, Fabric, Shell, Degree, C1, C2, C3, V_Color, PC1, PC2, CR1, CR2, Stripes, Solids, Comment )
SELECT TransactionsNew.ID1, TransactionsNew.TDate, TransactionsNew.BoxID, TransactionsNew.OldQty, TransactionsNew.Adjustments, TransactionsNew.AdjRemove, TransactionsNew.NewQty, TransactionsNew.Initials, TransactionsNew.Aisle, TransactionsNew.Sect, TransactionsNew.Box, TransactionsNew.Fabric, TransactionsNew.Shell, TransactionsNew.Degree, TransactionsNew.C1, TransactionsNew.C2, TransactionsNew.C3, TransactionsNew.V_Color, TransactionsNew.PC1, TransactionsNew.PC2, TransactionsNew.CR1, TransactionsNew.CR2, TransactionsNew.Stripes, TransactionsNew.Solids, TransactionsNew.Comment
Running the query gives the error "74 records cannot be inserted due to key violations". It will move all the other records. The destination table, Transactions2, is a new table with no data. Of course it has data after I run the query.
I have checked the original table, and I do not see duplicate keys. Does anyone have any idea what might cause that error?
The reason why I am inserting the data into a new table is because of another error. While adding new records, it gives a run-time error 3022 - "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."
Here is the code causing the error:
'create a new transactions record
'values from comboboxes and textboxes are moved
' to the table fields
!BoxID = ID
!OldQty = Qty.Value
Qty.Value = UpdateQty
!NewQty = Qty.Value
!Initials = txtInitials.Value
!Comment = txtComment.Value
If txtSubtract.Value <> "" Then
!adjustments = txtSubtract.Value * -1
ElseIf txtAdd.Value <> "" Then
!adjustments = txtAdd.Value
!Aisle = Aisle.Value
!Sect = Sect.Value
!Box = Box.Value
!Fabric = Fabric.Value
!Shell = Shell.Value
!Degree = Degree.Value
' !C1 = C1.Value
' !C2 = C2.Value
' !C3 = C3.Value
!V_Color = V_Color.Value
!PC1 = PC1.Value
!PC2 = PC2.Value
!CR1 = CR1.Value
!CR2 = CR2.Value
!Stripes = Stripes.Value
!Solids = Solids.Value
'!Qty = Qty.Value
TransIDHold = !ID1 'save id for print routine
The error occurs on the .Update statement. I have already stepped through the code and know that the value for ID1 is not already a key in the table.
Any suggestions? Is there a utility I can run to repair the table that might get rid of the error?
I do get rid of the error after inserting the data into a new table and then using that new table for the updates. However, it is missing the 74 records "due to key violations".