how to identify field value from the last inserted record?

S

subzizo

Hi all
I need to identify a field value from the last inserted record cause i need
to use it to update fields in another table?

thanks 4 efforts
 
A

Allen Browne

How are you addig the records?

If you are adding them to a Recordset, you can use the LastModified bookmark
to find the record.

If you are executing an Append query, the example below shows how to
retrieve the primary key value of the new record. Note that this works in
Access 2000 and later only (i.e. JET 4):

Function ShowIdentity() As Variant
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = DBEngine(0)(0)
db.Execute "INSERT INTO MyTable ( MyField ) SELECT 'nuffin' AS Expr1;"

Set rs = db.OpenRecordset("SELECT @@IDENTITY AS LastID;")
ShowIdentity = rs!LastID
rs.Close

Set rs = Nothing
Set db = Nothing
End Function
 
Top