Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return autonumber in Access like @@Identity

Status
Not open for further replies.

objuan

Programmer
Jun 27, 2002
13
0
0
US
Can anyone tell me how to return the AutoNumber from Access much like you can return the @@Identity in SQL?
 
Here's how I did it:

'First I execute a command object to insert a new record
objCmd.ExecuteScalar()

'Immediately after, I reset the command object's text
'property to the value below, set its command type (I'm
'using stored queries in Access, hence specifying
'commandtype.text...you may not have to do that line)
'and execute the command. This will return the new
'autonumber.
objCmd.CommandText = "Select @@Identity"
objCmd.CommandType = CommandType.Text
Return objCmd.ExecuteScaler()

hth, and let me know if you need anythign else.

D'Arcy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top