Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrive Autonumber in Access after insert

 
Wilson Hui
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I retrive Autonumber in Access after insert a new record?
Thanks in advance.
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can just select the Autonumber fieldname where a part of the record (try and pick something unique) matches the data you have just inserted. AutoNumbers are just stored as numbers so you can handle them as ints.
 
leo donahue
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Wilson Hui:
How can I retrive Autonumber in Access after insert a new record?
Thanks in advance.

You can use something like this:
Select Max(AutoNumberField) from Table Where SomeCondition
You mention that you want to retrieve the AutoNumber "AFTER" you insert a new record, just curious why you want to do this. There are other ways to do what I think you might be trying to do here.
 
Jason Cox
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"SELECT @@IDENTITY" should return the last value of the last autonumber field you called.
It needs to be the VERY NEXT database call after your insert though. Otherwise it may not work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic