Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ADO - ? autonumber after update

Posted on 1998-12-04
3
Medium Priority
?
237 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 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

916 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