• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 389
  • 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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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