Solved

ADO - ? autonumber after update

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

758 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

19 Experts available now in Live!

Get 1:1 Help Now