BruceM said:
This link shows one way of creating a sequential number, which is probably
what you want.
http://www.rogersaccesslibrary.com/download3.asp?SampleName=AutonumberProblem.mdb
"Form1 illustrates how to use the DMax function to simulate the action of
the Autonumber field."
That doesn't sound correct. If you explicitly insert the maximum INTEGER
value into an autonumber column it doesn't interrupt the generated sequence
but would cause a DMAX+1 algorithm to error, so that can't be the correct
algorithm for autonumber.
As a hint of how autonumber actually works in Jet, plus why an autonumber
column should perhaps always be constrained as UNIQUE, try the following VBA
code which uses large (and significant) seed values:
Sub autonum_test()
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 Test1 (" & _
" ID1 INTEGER IDENTITY(1, 1073741824)" & _
" NOT NULL, insert_sequence" & _
" INTEGER);"
.Execute _
"CREATE TABLE Test2 (" & _
" ID2 INTEGER IDENTITY(1, 1073741825)" & _
" NOT NULL, insert_sequence" & _
" INTEGER);"
.Execute _
"CREATE TABLE Digits (nbr INTEGER);"
.Execute _
"INSERT INTO Digits VALUES (0);"
.Execute _
"INSERT INTO Digits (nbr) SELECT DT1.nbr" & _
" FROM (SELECT 1 AS nbr FROM Digits UNION" & _
" ALL SELECT 2 FROM Digits UNION ALL SELECT" & _
" 3 FROM Digits UNION ALL SELECT 4 FROM Digits" & _
" UNION ALL SELECT 5 FROM Digits UNION ALL" & _
" SELECT 6 FROM Digits UNION ALL SELECT 7" & _
" FROM Digits UNION ALL SELECT 8 FROM Digits" & _
" UNION ALL SELECT 9 FROM Digits ) AS DT1;"
.Execute _
"INSERT INTO Test1 (insert_sequence) SELECT" & _
" nbr FROM Digits;"
.Execute _
"INSERT INTO Test2 (insert_sequence) SELECT" & _
" nbr FROM Digits;"
Dim rs
Set rs = .Execute( _
"SELECT DISTINCT 'insert_sequence'," & _
" 'autonumber_repeats', 'autonumber_wraps' FROM" & _
" Test1 AS T1" & vbCr & "UNION ALL SELECT" & _
" T1.insert_sequence & CHR(9)," & _
" T1.ID1 & STRING(IIF(LEN(CSTR(T1.ID1))" & _
" < 6, 2, 1), CHR(9)), T2.ID2 FROM" & _
" Test1 AS T1, Test2 AS T2 WHERE" & _
" T1.insert_sequence= T2.insert_sequence;")
MsgBox rs.GetString
End With
Set .ActiveConnection = Nothing
End With
End Sub
Jamie.
--