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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Primary key of a new post

Status
Not open for further replies.

n0nick

Programmer
Apr 28, 2005
32
NO
Im using Access database on my ASP pages and I have one question:

Lets say I got a form for registering new users. How can I get the autogenerated number, called userID ( is also primary key in the table ) that was created for this new user without have to make a new sql query to search for this user after creating it?
 
Save it somewhere after generating it and then call that location when you need it.

AvGuy
 
I don't think you understand my question. This "userID" is autogenerated by MS Access, so when i send INSERT query to database, MS Access is generating a ID for this user and my question is how can I get this userID?

I know that I can use SELECT query,after the user is inserted and search after this user in the table with the field-information I just stored but this is not effective...

So my question is; does it exist any function that return autogenerated ID after a INSERT query?

 
If you issue a select @@identity on the same connection as the insert, you should get the latest autonumber (VB/VBA code):

[tt]dim cn as adodb.connection
dim rs as adodb.recordset
' instantiate and open your connection
cn.execute "your insert"
set rs=cn.execute("select @@identity",,adcmdtext)
msgbox rs.fields(0).value[/tt]

Roy-Vidar
 
tnx a lot, this was what I was looking for!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top