Retrieve the last-assigned autonumber value : Autonumber « Access « VBA / Excel / Access / Word






Retrieve the last-assigned autonumber value

 
Sub LastAutonumber()
    Dim cmd As ADODB.Command
    Dim rst As ADODB.Recordset
    Set cmd = New ADODB.Command
    Set rst = New ADODB.Recordset

    cmd.ActiveConnection = CurrentProject.Connection
    cmd.CommandText = "INSERT INTO Customers2 " & _
        "(CompanyName, IntroDate, CreditLimit) " & _
        "VALUES ('Test Company', #1/1/2007#, 100) "
    cmd.Execute
    rst.ActiveConnection = CurrentProject.Connection
    rst.Open ("SELECT @@Identity as LastCustomer FROM tblCustomers")

End Sub

 








Related examples in the same category

1.Controlling Autonumber Fields