I table a table in MS Access which had a primary key
(AutoNumber). A few rows have been added to this table.
What I need to know is before I add a new row, what will
the primary key be??
I could loop through the rows and get the last key and add
one to it but is this safe?
Are there better ways to do this?
In general, for columns with the autonumber attribute, there is no reliabe
mechanism for determining what the next primary key will be. The reliable
method works after the row has been inserted - all you have to do is fetch
the value from the SELECT @@IDENTITY sql statement. Here is a link that may
help...
http://msdn.microsoft.com/library/en-us/dnacc2k/html/acintsql.asp
and here is a snip from the document:
Note The @@IDENTITY variable listed in the previous SQL statements can be
executed only through the Jet OLE DB provider and ADO; .... the variable is
set only when records are inserted through programming code. ... the value
of @@IDENTITY is only accurate immediately after adding a record from code.
regards
roy fine
"W Akthar" <wak...@hotmail.com> wrote in message
news:5ebc01c42ddf$2fb710e0$a301...@phx.gbl...