Geting primary key from newly created record (DAO.Recordset)

  • Thread starter Thread starter Niklas Östergren
  • Start date Start date
N

Niklas Östergren

Hi!

How do I get the primary key from a newly added record in a DAO.Recordset?

TIA!
// Niklas
 
Niklas,

Am I guessing correctly that you are talking of a situation where the PK
field is an autonumber, and the record is added through code? If that's
correct, then the PK autonumber is assigned as soon as you execute
rst.AddNew, so anytime after this and before you move to a new record you
can get the PK value by means of rst.Fields("PKFieldName"). You can do so
even before the rst.Update is executed, it doesn't make a difference. All
that's required is the PK field to be included in the recordset SQL string
(if not a whole table).

HTH,
Nikos
 
Hi!

Thanks a lot, just what I needed to know!

Yes, you where asuming right. I do add the records by code and yes PK is a
autonumber.

Thanks a lot agin! Now I´ll stay at work and work a little bit more on this
before I go home and having anice weekend! :-)

// Niklas
 
Back
Top