Filling in voids in the id number

T

TES

My first column is the key and ID number for each record. One of my users
(before I locked the table) voided several of the records, and now the record
number and Id number no longer match. Is there a way to back fill the key-id
number with dummy records so the rows line up.

Thanks……
 
S

Stefan Hoffmann

hi Tes,

My first column is the key and ID number for each record. One of my users
(before I locked the table) voided several of the records, and now the record
number and Id number no longer match. Is there a way to back fill the key-id
number with dummy records so the rows line up.
If you need a continuous number without gaps, then you must calculated
it before storing the records. You cannot use an auto number for that
purpose.

Use

Nz(DMax("number", "tableName"), 0) + 1

to calculate it. E.g. in the before insert event of a form:

Private Sub Form_BeforeInsert(Cancel As Integer)

Me![number] = Nz(DMax("number", "tableName"), 0) + 1

End Sub



mfG
--> stefan <--
 
K

KARL DEWEY

If that field is an autonumber you can Compact & Repair, close Access, open
Access, and append missing records.
 
J

John W. Vinson

My first column is the key and ID number for each record. One of my users
(before I locked the table) voided several of the records, and now the record
number and Id number no longer match. Is there a way to back fill the key-id
number with dummy records so the rows line up.

Thanks……

Ummmm...

You don't want to do that.

An Autonumber has one purpose, and one purpose ONLY: to provide a meaningless
unique identifier.

They are *NOT* "record numbers". They will always have gaps; not only will
deleting a record leave a permanent gap, so will starting to enter a record
and then hitting <ESC> twice to cancel the entry.

If you want a gapless, sequential number, don't use an Autonumber field at
all; use a "custom counter" (a long integer field with VBA code to assign the
value).

But think about it: do you really want meaningless, dummy records with no data
inserted into your table, just to keep the ID sequential? What benefit does it
serve to do so?
 
J

Jeff Boyce

In addition to advice offered else-thread, please be aware that the number
in the bottom left (I believe this is what you mean by "record number") is
NOT a record number, it's merely a count of records. If you change the sort
order, you'll still have the same number of records, but what you THOUGHT
was #1 could be #19 or #99 or #12345.

Does this mean you are trying to do this directly in the table? If so, STOP
NOW! Table store data. Forms display data.

Good luck!

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 pseudocode 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.
 

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