>Hello everyone,
>
>
>Is it possible to INSERT data and retrieve the new @@IDENTITY in one single instruction With ADO connection and SQLServer
>
>Ex:
>
>Connection.execute " INSERT INTO MyTable (MyField) VALUES ('Myvalue')
> SELECT @@IDENTITY AS 'MyIdentity' "
>
>MyNewIdentity = 'MyIdentity'
Sure. This the way:
strsql = "SET NOCOUNT ON " & _
"INSERT INTO Applications(description) VALUES('Test26') " & _
"SELECT @@IDENTITY " & _
"SET NOCOUNT OFF"
mrst.Open strsql, mcn
msgbox mrst(0)
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com