Hi. I have used @@IDENTITY before without any problems but, for some reason, I cannot get it to work in a database I am working on. I have pasted my code below. The message always says that the value is 0 but the new record is in fact created.
Maybe I am missing something obvious? The code below is in a module.
We are using Access 2010 with a SQL Server 2000 backend.
Public Sub testgetLastID()
Public Sub GetLastID()
Dim db As Database, rs As DAO.Recordset
DoCmd.RunSQL "INSERT INTO dbo_vwOrders(CustomerID) VALUES(6)"
Set rs = CurrentDb.OpenRecordset("SELECT @@IDENTITY As NewID FROM dbo_vwOrders", dbReadOnly)
newid = rs("NewID")
MsgBox "newid " & newid
Set rs = Nothing