If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
update number field automatically?
I have an existing table that has a number field as the primary key. I want
it to replicate the autonumber feature by adding the next number in sequence when a new record is added, but I can't change it to an autonumber field and keep the existing data. Can it be done? Thanks! Pat |
#2
|
|||
|
|||
update number field automatically?
Create a new table identical to your existing table, except make the number
field an AutoNumber. Append the existing table to the new table. The next value for the AutoNumber field will be one more than the largest value already used. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Patttt" wrote in message ... I have an existing table that has a number field as the primary key. I want it to replicate the autonumber feature by adding the next number in sequence when a new record is added, but I can't change it to an autonumber field and keep the existing data. Can it be done? Thanks! Pat |
#3
|
|||
|
|||
update number field automatically?
Thanks for your quick reply, Doug. Unfortunately, the original data starts
with number 13, and if I do it this way, it starts with number 1. Is there a way to get an autonumber field to start with #13? Pat "Douglas J. Steele" wrote: Create a new table identical to your existing table, except make the number field an AutoNumber. Append the existing table to the new table. The next value for the AutoNumber field will be one more than the largest value already used. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Patttt" wrote in message ... I have an existing table that has a number field as the primary key. I want it to replicate the autonumber feature by adding the next number in sequence when a new record is added, but I can't change it to an autonumber field and keep the existing data. Can it be done? Thanks! Pat |
#4
|
|||
|
|||
update number field automatically?
The Access Autonumber data type is designed to provide a unique row
identifier. It is not guaranteed to be sequential, and it is generally unfit for human consumption. If you need a guaranteed-sequential numbering system, you'll have to create a procedure that finds the current maximum number and adds one. Fortunately, this is fairly simple, and you can find examples search on-line for "custom autonumber". Good luck! Regards Jeff Boyce Microsoft Office/Access MVP "Patttt" wrote in message ... I have an existing table that has a number field as the primary key. I want it to replicate the autonumber feature by adding the next number in sequence when a new record is added, but I can't change it to an autonumber field and keep the existing data. Can it be done? Thanks! Pat |
#5
|
|||
|
|||
update number field automatically?
On Fri, 12 Dec 2008 14:04:10 -0800, Patttt
wrote: I have an existing table that has a number field as the primary key. I want it to replicate the autonumber feature by adding the next number in sequence when a new record is added, but I can't change it to an autonumber field and keep the existing data. Can it be done? Thanks! Pat You can use a bit of VBA code in the Form's BeforeInsert event (yes, you must use a Form, table datasheets have no usable events): Private Sub Form_BeforeInsert(Cancel as Integer) Me!IDField = NZ(DMax("[IDField]", "[tablename]")) + 1 End Sub -- John W. Vinson [MVP] |
#6
|
|||
|
|||
update number field automatically?
As I wrote, you need to append the original data to the new table before you
start using it. Once the row with number 13 is in the table, the next number assigned should be 14. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Patttt" wrote in message news Thanks for your quick reply, Doug. Unfortunately, the original data starts with number 13, and if I do it this way, it starts with number 1. Is there a way to get an autonumber field to start with #13? Pat "Douglas J. Steele" wrote: Create a new table identical to your existing table, except make the number field an AutoNumber. Append the existing table to the new table. The next value for the AutoNumber field will be one more than the largest value already used. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Patttt" wrote in message ... I have an existing table that has a number field as the primary key. I want it to replicate the autonumber feature by adding the next number in sequence when a new record is added, but I can't change it to an autonumber field and keep the existing data. Can it be done? Thanks! Pat |
Thread Tools | |
Display Modes | |
|
|