Solved

ADO - ? autonumber after update

Posted on 1998-12-04
3
231 Views
Last Modified: 2013-12-25
Using ADO  2.0  and Access 97 - How can you find out what the autonumber  id of a record just added is? There is no Lastmodified property for an ADO recordset.
0
Comment
Question by:mdwyer
3 Comments
 
LVL 3

Expert Comment

by:vbWhiz
ID: 1497985
I personally never use the autonumber feature of any database. You can check out my answer to Q.10104529, my sample uses another table to hold the last used ID for a given table. By using your own ID number routine you have more control of the ID's and a number won't be re-used if the record is deleted and the database is compacted.

URL for Q.10104529:

http://www.experts-exchange.com/topics/comp/lang/vbdatabases/Q.10104529

[-Note- the sample uses DAO - so I am performing a seek rather than opening a resultset but the concept is there.]
0
 
LVL 3

Accepted Solution

by:
hakyemez earned 100 total points
ID: 1497986
answer...
'Codes
'table1 fields id as autonumber,text as string*50
'cn --> adodb.connection
'rs --> adodb.recordset

Sub MyAnswer()
  dim rs as new adodb.recordset
  cn.BeginTran
  rs.open "table1",cn,adopenkeyset,adlockoptimistic,adcmdtable
  rs.addnew
  rs(1)="x"
  rs.update
  rs.close
  rs.open "select max(id) from table1",cn,adOpenStatic,adLockReadOnly
  debug.print rs(0) ' value return inserted autonumber
  rs.close
  cn.RollbackTran
  set rs=nothing
End Sub
0
 

Author Comment

by:mdwyer
ID: 1497987
As it turrns out - I was originally specifying a CursorLocation of adUseClient for my recordset . I switched to adUseServer and my autonumber ID was then visible after  the update method.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

932 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

14 Experts available now in Live!

Get 1:1 Help Now