Copy Record w/ primary key

  • Thread starter Thread starter llw
  • Start date Start date
L

llw

I need to duplicate records except the key field will be
different. When we copy and paste append, we get a
duplicate key error. Is there a way to populate the key
field with the new value and copying rest of the record
easily? I created an input box for the user to fill in
the new value but only know how to move rest of the data
with field by field code. Any shortcuts?
Thanks
 
Primary Keys are meant to be unique, so although there is a way to insert
the data (including its PK) into the table, there's only one way to ensure
that you can have duplicate keys - and that's to remove the index from the
PK. That's something you should certainly avoid!

To copy the data into the table, letting Access assign a key, just don't
include the PK field in the insert query's statement. For example, if we
have two identical tables that each have an ID field (PK), a MyName field
and an Address field, the insert query to use would be:
INSERT INTO tblTable1 (MyName, Address) SELECT MyName, Address FROM
tblTable2

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Back
Top