An Autonumber has one
purpose, and one purpose only: to provide an almost-guaranteed (there
are bugs) unique key.
I think you give autonumber too much credit <g>. Autonumber *does* one
thing: it generates a number or GUID according to an algorithm
(increment, random, new GUID).
There is nothing about autonumber that guarantees it will be unique.
If you want the value to be unique in a column you have to apply a
UNIQUE constraint, so there's nothing special about autonumber in this
regard. Even GUID is not guaranteed to be unique in all
circumstances!
The purpose for which an autonumber is used is an entirely different
matter. Using an autonumber as a key could be a fallacy if you
consider that a key needs to exist in the reality being modelled and
pretty much everyone says you shouldn't expose an autonumber.
Here's a quick example of how generated autonumber values (ID) can
repeat:
Sub repeating_autonum()
' Kill Environ$("temp") & "\DropMe.mdb"
Dim cat
Set cat = CreateObject("ADOX.Catalog")
With cat
.Create _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & _
Environ$("temp") & "\DropMe.mdb"
With .ActiveConnection
.Execute _
"CREATE TABLE Test (" & _
" ID INTEGER IDENTITY(1, 1073741824)" & _
" NOT NULL, insert_sequence" & _
" INTEGER);"
.Execute _
"INSERT INTO Test (insert_sequence)" & _
" VALUES (1);"
.Execute _
"INSERT INTO Test (insert_sequence)" & _
" VALUES (2);"
.Execute _
"INSERT INTO Test (insert_sequence)" & _
" VALUES (3);"
.Execute _
"INSERT INTO Test (insert_sequence)" & _
" VALUES (4);"
.Execute _
"INSERT INTO Test (insert_sequence)" & _
" VALUES (5);"
.Execute _
"INSERT INTO Test (insert_sequence)" & _
" VALUES (6);"
.Execute _
"INSERT INTO Test (insert_sequence)" & _
" VALUES (7);"
.Execute _
"INSERT INTO Test (insert_sequence)" & _
" VALUES (8);"
.Execute _
"INSERT INTO Test (insert_sequence)" & _
" VALUES (9);"
Dim rs
Set rs = .Execute( _
"SELECT ID, insert_sequence" & _
" FROM Test;")
MsgBox rs.GetString
End With
Set .ActiveConnection = Nothing
End With
End Sub
Jamie.
--