Hi all,<BR><BR>This has probably been asked before, but can someone please post or direct me to a VB example of how to obtain the ID of a newly inserted record? And if at all possible, one that works with MS-Access.<BR><BR>objConn.Open()<BR>RecordsAffected = objCmd.ExecuteNonQuery()<BR><BR>WHAT CODE???<BR><BR>Thanks,<BR>D.<BR>Hi. You mean something like this:<BR><BR> strSqlGetPrimaryKey = " "& _<BR> " SELECT" & _<BR> " @@IDENTITY" & _<BR> " FROM" & _<BR> " yourTable"<BR><BR>objCommand = New OleDbCommand(strSqlGetPrimaryKey, objConn)<BR><BR>Dim objReader AS OleDbDataReader<BR> objReader = objCommand.ExecuteReader()<BR> <BR>Dim intLastCreatedID AS Integer<BR> While objReader.Read()<BR> intLastCreatedID = objReader.GetInt32(0)<BR> End While<BR> <BR> objReader.Close()<BR> objConn.Close()<BR><BR>@@IDENTITY will only work if you have an auto increment field, since that is the value it brings back.Hi,<BR><BR>I mean after a new record is added to the database, how do you then obtained the ID (pk) of that record?If you need to get the ID (and it has to be a auto increment column) back after a record is added into a table(!) in your database, then you do it just like I showed you in my last post. <BR><BR>Read this: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q232144Hi,<BR><BR>Sorry, I read your posting wrong and implemented it wrong. I tried again it it works great!! Thanks! One last question for you:<BR><BR>Do you know which databases that @@IDENTITY works for? Access 2000 and SQL I know it does, but are there others?<BR><BR>Thanks again,<BR>D.I think the @@IDENTITY call is a pretty standard call, which means you can use it with most databases. I've only used it myself against access, MSsql and Sybase, but as I said, I'm pretty sure you can use it towards other databases as well. Don't quote me on that though 
