Re-number an Autonumber

  • Thread starter Thread starter ADonMS
  • Start date Start date
A

ADonMS

Is it possible to re-number an Autonumber that is the primary key on a table?
For some reason my autonumber is skipping in sequential order and when I
create query, I'm missing a row that is listed on the table.
 
hi,
Is it possible to re-number an Autonumber that is the primary key on a table?
For some reason my autonumber is skipping in sequential order and when I
create query, I'm missing a row that is listed on the table.
Basically, yes. But the normal autonumber data type is only guaranteed
to increase, not to be without gap. If you need an increasing sequence
without gaps then you need to create it by yourself, e.g. in a forms
before update event:

Public Sub Form_BeforeUpdate(Cancel as Integer)

Me![SequenceField] = Nz(DMax("SequenceField", "yourTable"), 0) + 1

End Sub


mfG
--> stefan <--
 
If you are talking about an Access Autonumber field, no. Access
automatically generates that value, and you have no control over it.

But the purpose of an Access Autonumber is to provide a unique row
identifier. It isn't guaranteed to be sequential, and is generally unfit
for human consumption.

It sounds like you are looking at the "1 of n" navigation information at the
bottom of a table display and expecting those values to match your
autonumber field. AIN'T GONNA HAPPEN! Those navigation numbers change
every time you re-sort the table. The Autonumbers are set and never change.

If this doesn't resolve your issue, please provide more detailed
description...

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or psuedocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
Thanks, for input.


Stefan Hoffmann said:
hi,
Is it possible to re-number an Autonumber that is the primary key on a table?
For some reason my autonumber is skipping in sequential order and when I
create query, I'm missing a row that is listed on the table.
Basically, yes. But the normal autonumber data type is only guaranteed
to increase, not to be without gap. If you need an increasing sequence
without gaps then you need to create it by yourself, e.g. in a forms
before update event:

Public Sub Form_BeforeUpdate(Cancel as Integer)

Me![SequenceField] = Nz(DMax("SequenceField", "yourTable"), 0) + 1

End Sub


mfG
--> stefan <--
 
Thanks, Jeff. That's what I was doing. So, I no longer need to think about
the sequential ordering in this case.
Much appreciated info.
 
Back
Top