Solved

Access 2007 - Return ID of last record inserted

Posted on 2011-02-25
6
319 Views
Last Modified: 2012-05-11
I need a way to return the ID of the last record inserted into a table.  I've found a few places out there with commentary on this, but I'm not sure what the best practice is to make this happen.

Are there transactions in access?  Should I include the insert and the ID retrieval as part of the same transaction so I can be sure I'm getting the correct ID back?
0
Comment
Question by:JosephEricDavis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 34981209


=Dmax("ID","YourTable")
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 34981244
Now this is a bit tricky because my above post assumes that the ID field is an autonumber field.

I'll explain....

A table does not really know what record is "Last"
The "last record" will depend on how the table is sorted.
It can also mean the record with the most recent Day/Time stamp.

So you will have to clearly define "Last Record"
0
 
LVL 7

Author Comment

by:JosephEricDavis
ID: 34981273
What about Transactions?  How do a perform a Transaction?
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 34982364
<What about Transactions?  How do a perform a Transaction?>
I'm confused?
I thought the one question here was determining the Last Record?

"Transaction" as they are known in SQL Server, do not exist in MS Access.
You can Access transactions via Access SQL (TSQL variant)
http://msdn.microsoft.com/en-us/library/bb208950%28v=office.12%29.aspx
http://msdn.microsoft.com/en-us/library/sx0e0xze.aspx
...I am sure you can google mor hits depending on your exact needs.

JeffCoachman
0
 
LVL 7

Author Comment

by:JosephEricDavis
ID: 34998613
Actually Access does have transactions, as can be seen here.
http://msdn.microsoft.com/en-us/library/bb243806%28v=office.12%29.aspx

I tried them and they work as just as one might think transactions work.  So I can't give you points for your response on that part of my question.  I can just give you points for the =Dmax("ID","YourTable") comment.

Thanks
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 34999612
<Actually Access does have transactions,>
This is more of a semantics issue...
Transaction in DAO, yes, but not in Access directly.
For example there are no "Transaction" properties or setting in Access (forms) directly.

It all depends on what you are referring to specifically when you say "Access"
As the link states:
"The Microsoft Access database engine supports transactions through the DAO"

So like A 2005 Ford Taurus will "Support" Turbo/supercharging, remember that Turbo/supercharging it is not offered with the car as standard.

See the note in the link for info that Transactions in Access DAO are not the same as Transactions in a true Client/Server architecture.
So if you are looking some specific Translation functionality, it may not be the same in Access...

;-)

JeffCoachman
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

729 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