Append Query Key Violation (as used in Create Similar Record)

vbaDev

Registered User.
Local time
Yesterday, 19:45
Joined
Feb 26, 2007
Messages
64
I have a database of Assessments, each record having multiple subforms.

I am working on a button, which creates a "similar" (same) assessment, copying over all the subform records/selections.

So, after I actually insert a new assessment, pasting all the values from the original Assessment:

Code:
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend

I need to copy over subform contents, for which I use an Append Query (actually, I use its SQL in VBA code to pass it the right parameters).

Now, naturally, I ran into Key Violations, because taking 50 sub-records from the original they would have their own AutoNumber Keys (ID's) and I can't append them into the same table.

My question: how do I copy over the same records (appending FROM and TO the same table) but cause the table to insert AutoNumbers for the records being appended?

Thanks!
 
Ok, nevermind, I'm sorry. All I needed to do was NOT include the ID field and the AutoNumber just does its thing.

It didn't work when I tried it, because I took ID out of the INSERT INTO part, but forgot to remove it from "SELECT" part. So it would tell me that the source and target fields didn't match. Now everything works fine.

Sorry!
 

Users who are viewing this thread

Back
Top Bottom