I was not saying that it was impossible to "reuse" missing numbers -- what I
was saying is that autonumber field itself will not reuse those numbers.
Yes, you can "insert" specific values for the autonumber field into new
records being inserted into the table. However, to identify what numbers are
"missing" will require additional code or tables where such gaps are
identified/tracked. The amount of programming needed for that often is more
complex than what most users seek for a "simple" setup to assign the next
sequential number if not using an autonumber.
--
Ken Snell
<MS ACCESS MVP>
You can.
Here is some code from the Immediate Window which:
· Which creates a table with a autonumber key_col.
· Auto-generates key_col=1.
· Starts to autogenerate key_col=2 but rolls back the transaction so
that key_col=2 is not actually created
· Creates a row key_col=3.
· Shows that key_col=2 was not autogenerated.
· Creates key_col=2.
· Shows that key_col=2 was created.
CurrentProject.Execute "CREATE TABLE Test (" & _
"key_col INTEGER IDENTITY(1,1) NOT NULL," & _
" data_col INTEGER NOT NULL UNIQUE)"
CurrentProject.Execute "INSERT INTO Test (data_col) VALUES (1)"
CurrentProject.BeginTrans
CurrentProject.Execute "INSERT INTO Test (data_col) VALUES (2)"
CurrentProject.RollbackTrans
CurrentProject.Execute "INSERT INTO Test (data_col) VALUES (3)"
set rs = CurrentProject.Execute("SELECT key_col, data_col FROM Test")
? rs.GetString
1 1
3 3
CurrentProject.Execute "INSERT INTO Test (key_col, data_col) VALUES (2,
2)"
set rs = CurrentProject.Execute("SELECT key_col, data_col FROM Test")
? rs.GetString
1 1
3 3
2 2