VBA - Determine last Inserted UID

Hi guys,

I wanted to know if it's possible to run an Insert statement on a table, and then determine what the UID (also the primary key) of that entry is?

Cheers guys!
LVL 4
Cyber-DrugsAsked:
Who is Participating?
 
mbizupCommented:
If it's an autonumber, Try this:

LastID = DMax("UID","YourTable")
0
 
Rey Obrero (Capricorn1)Commented:
not accurate in multiple user

Dmax("UID","TableName")
0
 
rockiroadsCommented:
How multi user is your database gonna be

if u use a recordset to add (one I prefer to use if u have several fields to add) then once u do AddNew, u get the UID number (if its a autonumber)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Cyber-DrugsAuthor Commented:
There will be one whole user of this amazingly big database (excuse the sarcasm :P )

So I can presume Dmax() will be safe?
0
 
mbizupCommented:
Yes.  If you wanted to expand, you'd need to do something else.
0
 
mbizupCommented:
For a multiuser database, Rocki's VBA suggestion would work, or this variation on the DMax, assuming you're tracking who creates the record:
Dmax("UID","TableName","CreatedBy = '" & currentUser & "'")
0
 
Cyber-DrugsAuthor Commented:
Cheers guys!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.