ar********@gmail.com wrote in news:1148550848.023918.189660
@g10g2000cwb.googlegroups.com:
in sql server you can retrieve the ID of the
newly added record using
@@IDENTITY,
SCOPE_IDENTITY or
IDENT_CURRENT
but those function dont have
equivalent in Access.
Jet OLE DB Provider Version 4.0 Supports SELECT @@Identity
A simple way to use this is to INSERT with a distinct ADODB Connection.
Sub temp()
Dim c As ADODB.Connection
Set c = New ADODB.Connection
With c
..ConnectionString = CurrentProject.BaseConnectionString
..Open
..Execute "INSERT INTO [Order Details] " _
& "(OrderID, ProductID, UnitPrice, Quantity, Discount) " _
& "Values (12, 23, 15.5, 12, 3/1000)"
Debug.Print .Execute("SELECT @@Identity").Collect(0)
' prints the autonumber of the newly inserted record
..Close
End With
Set c = Nothing
End Sub
--
Lyle Fairfield