Solved

VBA - Determine last Inserted UID

Posted on 2006-11-06
7
345 Views
Last Modified: 2008-03-10
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
Comment
Question by:Cyber-Drugs
7 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 300 total points
ID: 17882189
If it's an autonumber, Try this:

LastID = DMax("UID","YourTable")
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 200 total points
ID: 17882197
not accurate in multiple user

Dmax("UID","TableName")
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17882217
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17882234
There will be one whole user of this amazingly big database (excuse the sarcasm :P )

So I can presume Dmax() will be safe?
0
 
LVL 61

Expert Comment

by:mbizup
ID: 17882262
Yes.  If you wanted to expand, you'd need to do something else.
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 300 total points
ID: 17882299
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
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17882391
Cheers guys!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now