
ADODB.recordset.AddNew & returning ID ?!
The kb's articles I've seen basically suggest requerying the recordset to
refresh the data and then moving to the last record which is meant to be the
newly added record. That's fine providing the recordset is ordered on the
default ID field. Problem occurs if the recordset is ordered on a different
field, because then the requery will place the new record somewhere in the
middle of the recordset.
The workaround I use is call a sub routine within the save sub. The sub routine
opens a new instance of the recordset without an order by, meaning you can go
to the last record and get the ID value, but make sure you use the same
connection object as the first recordset.
Once you have the ID value place it into a variable and close the second
recordset.
Return to the first recordset, do a requery, followed by a find to go to the
newly added record, no matter where it is located in the recordset.
The process may sound unweidly, but it works in less than a second, and shows
the ID field value every time.
Dave
Quote:
> Anyone an idea?
> I open a recordset (table) and add new data.
> How can i retrieve the id of the new added record within the SAME recordset
> definition???
> Thanx.
> B.M.