I have been all over the web looking for a way to fix this, and all the answers seem to tell me that I am doing this correctly. I have inherited this Access / SQL Server database, and I cannot seem to get this piece to work.
I am executing a fairly basic SQL INSERT
query that works fine. I have checked it several times. Once the query executes, I am attempting to get the identity value back out of it to use for the rest of my code.
Here is my code:
db.Execute (SQLStr)
Set rs = db.OpenRecordset("SELECT @@IDENTITY")
InNo = rs(0)
Debug.Print InNo
rs.Close
db.Close
This always returns a value of 0 for InNo
. I have tried several different methods but I cannot seem to get this working.
I have also used this method from the SQL Server directly, and querying the @@Identity
works fine.
Thanks in advance.