I need to get the Autonumber (GUID) of the last record just entered into the table called Farmers. This is the code that I am using, but every time instead of getting the last AutoNo I keep getting 0. The Farmers table is a linked table in a separate Access database. I am working in Access 2000
Thanks
Function FindGUID()
Dim SQL As String, conn As ADODB.Connection, LastId As Integer, RS As ADODB.Recordset
Set conn = CurrentProject.Connection
SQL = "INSERT INTO Farmers ( Surname ) SELECT 'Jones' AS Surname "
conn.Execute (SQL)
SQL = "SELECT @@IDENTITY"
Set RS = conn.Execute(SQL)
LastId = RS(0)
Debug.Print LastId
RS.Close
Set RS = Nothing
conn.Close
Set conn = Nothing
FindGUID = LastId
End Function
Dim SQL As String, conn As ADODB.Connection, LastId As Integer, RS As ADODB.Recordset
Set conn = CurrentProject.Connection
SQL = "INSERT INTO Farmers ( Surname ) SELECT 'Jones' AS Surname "
conn.Execute (SQL)
SQL = "SELECT @@IDENTITY"
Set RS = conn.Execute(SQL)
LastId = RS(0)
Debug.Print LastId
RS.Close
Set RS = Nothing
conn.Close
Set conn = Nothing
FindGUID = LastId
End Function
Thanks