• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 397
  • Last Modified:

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!
0
Cyber-Drugs
Asked:
Cyber-Drugs
3 Solutions
 
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
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
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.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now