Lapchien,
If you're using this number for a primary key of some kind, you should
probably save yourself the trouble of "filling in the gaps" and just start
with the next available number. In your scenario, you'll have to identify
the missing numbers, store them somewhere, then use them one at a time and
mark each one as used (or delete it) until they're all gone. Almost
certainly not worth the trouble.
If you're concerned about having sequential ID numbers and your database
isn't very complicated, you could copy your data into a new table with a
fresh AutoNumber field.
But, if you are determined to find the missing numbers, try this:
dim i as long, rs as recordset, db as database
set db = Currentdb()
for i = 1 to dmax("ID","Table")
set rs = db.openRecordset("SELECT ID FROM Table WHERE ID = " & i & ";")
if rs.recordcount = 0 then
db.execute("INSERT INTO MissingIDs (ID) VALUE (" & i & ");")
endif
rs.close
next i
"Lapchien" <cc****@nospamplease.eclipse.co.uk> wrote in message
news:10***************@ananke.eclipse.net.uk...
I have list of numbers in a table (originally from autonumber in a
different database) from 1 to 1,000,000. The list is not in sequential order -
there are loads of numbers missing. How can I identify what numbers are
missing?
Thanks,
Lap
(I'd like to then use this 'missing number list' to use for new records,
instead of autonumber - I think I need to use DMax - can someone summarise
it's use..?)