You can use ADOX (Microsoft ADO Extensions for DDL and Security) to determine your autonumber field's current "Seed" value.
Public Function NextAutonumber(ByVal pTable As String, _
ByVal pAutonumField As String) As Long
Dim cat As Object
Set cat = CreateObject("ADOX.Catalog")
Set cat.ActiveConnection = CurrentProject.Connection
NextAutonumber = cat.Tables(pTable).Columns(pAutonumField).Properties("Seed")
Set cat = Nothing
End Function
Note this approach could give the wrong result in a multi-user situation ... if another user can sneak an INSERT
in between the time you retrieve the next autonumber and you actually do your INSERT
. If it's critical, you could verify whether you got the value you expected by checking SELECT @@Identity
after the INSERT
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…