Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 Get Back the Auto INcrement Value

Author  Topic 

Amjath
Yak Posting Veteran

66 Posts

Posted - 2007-01-29 : 01:45:43
Hi All,
I'm using Auto INcrement Column in my Access DB....
how to get back the currently generated Value by Auto Increment coulmn...
like @@Identity in Sql Server....

-Amjath

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2007-01-31 : 19:34:36
Hi Amjath

I'm assuming you are using DAO 3.x.

As soon as you use the .AddNew method the Autonumber field is available.
Public Sub CheckAuto()
Dim db As Database
Dim rst As Recordset

Set db = CurrentDb
Set rst = db.OpenRecordset("Table1")

rst.AddNew
Debug.Print rst.Fields("ID")
'rst.Update
rst.Close

Set rst = Nothing
Set db = Nothing
End Sub
Note that the Autonumber will increment whether or not you Update the recordset.

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page
   

- Advertisement -