Finding missing No (1 Viewer)

sbaud2003

Member
Local time
Tomorrow, 04:29
Joined
Apr 5, 2020
Messages
178
I want to find all the missing IDs in a table starting from 1 to the end of the Table. How can i do that and display the missing IDs
IDs are Primary and serially numbered. however one missed the seriality in entering.
 
Last edited:

ebs17

Well-known member
Local time
Tomorrow, 00:59
Joined
Feb 7, 2020
Messages
1,950
Something can only be missing if you have an idea of completeness. Therefore you would have to compare your table against a complete table.
SQL:
SELECT N.Num
FROM NumberTable AS N LEFT JOIN YourTable AS Y
ON N.Num = Y.ID
WHERE Y.ID Is Null
 

jdraw

Super Moderator
Staff member
Local time
Today, 18:59
Joined
Jan 23, 2006
Messages
15,386
Here is some info about autonumbers from UtterAccess.

What they are NOT:
1. Row (record) sequence numbers.
2. An "order of entry into the table" number
3. A "gapless" series of numbers.
4. Editable numbers.
5. A series of (necessarily) always increasing numbers.
6. Intended to be viewed/used by end users of the application.
7. Predictable (as to what the previous or next one in the table is/or will be).
8. Reassigned, once deleted or discarded
9. A predictor/indicator of the number of rows in a table.
10. Intended to be used to "rank" or "sort" or "number" rows returned from the table.
11. Necessarily used to determine the default order the rows may be returned from the table.
12. Indicative of or related to any TimeStamp field that may also be in the table row.

What they are:
1. Unique numbers used to identify individual rows in a table.
2. Automatically created by Access when a new row is "instanced" by Access.
3. Great/Outstanding/Essential for use as the Primary Key of a table.
4. Great/Outstanding/Essential for use as "link points" by Foreign Keys in other tables.
5. Unchanging, once assigned to a particular table row
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:59
Joined
May 7, 2009
Messages
19,246
however one missed the seriality in entering.
Autonumber can easily be "missed", when a users enters a New record and start typing and eventually bail out and discontinue adding the record.
it is not similar to a Cheque number where a missing 1 is very impotant.
what matters is that our teeth should not be gapped!
 

xavier.batlle

New member
Local time
Tomorrow, 00:59
Joined
Sep 1, 2023
Messages
28
I want to find all the missing IDs in a table starting from 1 to the end of the Table. How can i do that and display the missing IDs
IDs are Primary and serially numbered. however one missed the seriality in entering.
A simple way to do it would be:
Create a table with all the Id possibles (for example in Excel and attach that table)
Create a query with not matching records as @ebs17 has posted.
 

GPGeorge

George Hepworth
Local time
Today, 15:59
Joined
Nov 25, 2004
Messages
1,921
Piling on a bit, I know.

If gaps in a sequence of AutoNumbers is a problem, you've been doing it wrong.

I love the analogy to teeth, btw. Just a couple of weeks ago, I had to have some teeth extracted. The temporary gaps are a hassle, but I know exactly where they are. ;)

There are multiple gaps in AutoNumbers (or Identity values in SQL Server tables) in every database I have, but I have no idea where the gaps are and what values have been lost. And I don't even care!
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 23:59
Joined
Sep 12, 2006
Messages
15,662
Just write a quick VBA function to iterate the numbers and report the gaps.

You shouldn't expect an intact sequence with an autonumber. If you want an an intact sequence you need to manage the numbering yourself.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:59
Joined
Feb 19, 2002
Messages
43,371
If you need to avoid gaps, you need to start by preventing deletes. Then you need to generate your own sequence numbers. Assign them as the last line of code in the form's BeforeUpdate event and use a loop to capture duplicates in case another user is trying to insert records at the same time and you have a conflict.
 

Users who are viewing this thread

Top Bottom