Solved

ADO - ? autonumber after update

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

730 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