Solved

ADO - ? autonumber after update

Posted on 1998-12-04
3
232 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

816 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

10 Experts available now in Live!

Get 1:1 Help Now