Re: How to retrieve id of last inserted record in Access without using @@identity?



Thanks for your response, Marshall!

Best,
J.S.

--

"Marshall Barton" <marshbarton@xxxxxxxxxx> wrote in message
news:i0jeg199hp9kk8p8rso9sh6v3hif04cch4@xxxxxxxxxx
> Come on folks, an AutoNumber PK field can not be relied on
> to be anything other than unique. The AutoNumber value can
> go negative if enough records are added, and there are
> times(?) when Access might decide(?) to change it from
> increment to random.
>
> The date/time field is clearly the easiest way to reliably
> identify the order that records were entered. Given that,
> one way to get the latest record is:
>
> SELECT TOP 1 <field list>
> FROM <thetable>
> ORDER BY <datefield> DESC
>
> A way to lookup the PK field of the latest record:
>
> DLookup("PK", "thetable", "datefield = " &
> Format(DMax("datefield", "thetable"), "\#m\/d\/yyyy\#"))
>
> but that is pretty ugly and will be slow if done frequently.
>
> --
> Marsh
> MVP [MS Access]


.