Duplicate rows in ACCESS with primary key (autonum)

W

Winfried

Hi,

Probably this question came up hundred of times but I don't find no
link that fits my question in then web or groups.

M problem:
I want to duplicate one ACCESS data row (with ADO) of a table that has
a primary key called PS. In this duplicated row I want to do some
simple assignments and then I want to save this new data row. in my
table there is only one primary key called PS and some mre indices but
their values are not unique.

a) With the VBA code "Set rstClone = rstTable.Clone" I duplicate the
whole row.
b) With "rstTable.Addnew" I create a new row
c) With
For Each Feld In rstClone.Fields
If Feld.Name <> "PS" Then ' This is the element that
copntains the primary key
rstTable.Fields(Feld.Name).Value = Feld.Value
End If
Next Feld
d) Then I do some manipulation of some fields of the new created row
e) At last I want to save this row with "rstTable.Update"

I hoped that the system is so clever, looks for the next potential
number of PS and insert a new "PS" value automatically.

But I get the error message"The change you requested to the tabler 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.

Can someone help me where my error is respectively describe who I can
do it best and easiest.

Thank you in advanve.
Winfried
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top