|
|
 |
| Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

July 31st, 2008, 12:09 PM
|
|
Registered User
|
|
Join Date: Aug 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Insert Query Error & Run-Time Error 3022
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:
Code:
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
FROM TransactionsNew;
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:
Code:
With Me.TransactionsNew.Form.RecordsetClone
'create a new transactions record
'values from comboboxes and textboxes are moved
' to the table fields
.AddNew
!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
End If
!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
.Update
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".
|

July 31st, 2008, 12:17 PM
|
|
Registered User
|
|
Join Date: Aug 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well, I just checked again. There actually are duplicate keys - 74 of them.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |