A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

update number field automatically?



 
 
Thread Tools Display Modes
  #1  
Old December 12th, 2008, 11:04 PM posted to microsoft.public.access.tablesdbdesign
Patttt
external usenet poster
 
Posts: 15
Default 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  
Old December 12th, 2008, 11:12 PM posted to microsoft.public.access.tablesdbdesign
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default 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  
Old December 13th, 2008, 12:04 AM posted to microsoft.public.access.tablesdbdesign
Patttt
external usenet poster
 
Posts: 15
Default 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  
Old December 13th, 2008, 01:55 AM posted to microsoft.public.access.tablesdbdesign
Jeff Boyce
external usenet poster
 
Posts: 8,621
Default 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  
Old December 13th, 2008, 02:26 AM posted to microsoft.public.access.tablesdbdesign
John W. Vinson
external usenet poster
 
Posts: 18,261
Default 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  
Old December 13th, 2008, 01:10 PM posted to microsoft.public.access.tablesdbdesign
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:52 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.