How to get Identity value of Last Inserted Row

jack123

New member
Local time
Tomorrow, 03:41
Joined
Jun 22, 2009
Messages
7
Hi All,

I am having a table with one of the Column as SerialNo whose datatype is Autonumber...

whenever I Insert a row I want to get the SerialNo of that row..

In Sql Server , there is @@Identity so if we want last inserted row Serialno we write like this...

Select @@Identity

I want to ask What is the Equivalent of @@Identity in MS ACCESS 2007.

Please If any one knows the solution ..help me out

Thanks in Advance..
 
This is a snippet from a VB app that uses Access as a back end that uses the code you are looking for

Code:
Function CreateSession(WhoAmi As String)
Dim iSql As String
Dim sSql As String

'Saves the current login record back to the server
Dim NextSessionId As Integer
Dim Tbl As New ADODB.Recordset

        Set Tbl = New ADODB.Recordset
            sSql = "Select * From TblLoginSessions Where fldOrganisation = '" & szOrgCode & "'"
            
        With Tbl
            .Open sSql, MasterDbConn, adOpenKeyset, adLockOptimistic, adCmdText
            .AddNew
            .Fields("fldOrganisation").Value = szOrgCode
            .Fields("fldUserName").Value = WhoAmi
            .Fields("fldComputerName").Value = StrComputerName
            .Fields("fldLoginEvent").Value = Now()
            .Update
            .Close
        End With
        Set Tbl = MasterDbConn.Execute("Select @@identity As XPropertyID")
        LngLoginKey = Tbl.Fields("XPropertyID").Value
        Set Tbl = Nothing

End Function
 

Users who are viewing this thread

Back
Top Bottom