Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 31st, 2008, 12:09 PM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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".

Reply With Quote
  #2 (permalink)  
Old July 31st, 2008, 12:17 PM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I just checked again. There actually are duplicate keys - 74 of them.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time error '3464': ivanlaw Access VBA 8 December 28th, 2007 09:02 AM
run-time error(s) Chacko C++ Programming 0 March 4th, 2007 02:28 PM
run time error ashishroyk Java GUI 0 October 8th, 2004 02:42 AM
Run Time Error JBond Access VBA 0 May 27th, 2004 10:50 AM
RUN-TIME ERROR compcad Beginning VB 6 2 May 21st, 2004 03:01 AM



All times are GMT -4. The time now is 01:36 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.