Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autonumber problem

Status
Not open for further replies.

LATECHmatt05

Technical User
Jun 23, 2004
11
US
Hello,

I have a problem I want to duplicate a record using a button in a form. The only problem is when I do it changes the autonumber Identifying number. I need this number to stay the same. Is there anyway to code a button in a form that duplicates a record without incrementing the value in the autonumber field?

Many thanks,

Matthew
 
Hi,

The autonumber field does as it says, which is increments the number by 1 each time a new record is added. Generally autonumber fields are used as primary keys anyway, for the simple fact that they will be unique. What I would recommend is to the following:

1) Set the field up as a number field and then each time a record is added use the DMAX function to find the maximum value in the field and then increment it by 1.

2) Obviously for this you will need to create a primary key, so what I would suggest also is to set up an autonumber field as the primary key because you need uniqueness for indexing purposes even though the records are the same.

Hope this helps


Andrew
 
You could create another number field in your table. When duplicating a record, the value of the autonumber field would be put in the new field and the autonumber field in the new record would be incremented as usual (and would continue working as a primary key).

You could also set the new field equal to the primary key value in each record unless the new field already contained a value. When the autonumber field and the new field contain different values, then the record is a copy of another record (identified by the value in the new field).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top