By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,293 Members | 1,579 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,293 IT Pros & Developers. It's quick & easy.

Inserting record with Microsoft Access

P: n/a
Hi,

I am developing a python script which add records to
a microsoft access tables. All my tables have autogenerated number
fields. I am trying to capture the number generated from the insert but
I am not exactly sure how to do that after an insert.

Thanks,
Jeff

Feb 9 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I can't remember the detail right now but look at SELECT @@IDENTITY.

Cheers,
Davy M

Feb 9 '06 #2

P: n/a
"jeffhg582003" <je**********@yahoo.com> wrote in
news:ma***************************************@pyt hon.org:
fields. I am trying to capture the number generated from the insert but I am not exactly sure how to do that after an insert.


Other folks have pointed you to "select @@identity" but I thought I
should mention that if you use ADO with the AddNew method then
autonumbers are magically retrieved. Something like this should work:

rs.AddNew()
rs.Fields("somefield").Value= "Blah"
rs.Update()
print "Autonumber is", rs.Fields("TheAutonumberField").Value

This didn't always work so ADO and the MDB can't be ancient versions.

SQL Server will also do this but the recordset must be opened with:

rs.CursorLocation= constants.adUseServer
rs.Open("Tablename", conn, constants.adOpenKeyset,
constants.adLockOptimistic)

Feb 9 '06 #3

P: n/a
"jeffhg582003" <je**********@yahoo.com> wrote:

I am developing a python script which add records to
a microsoft access tables. All my tables have autogenerated number
fields. I am trying to capture the number generated from the insert but
I am not exactly sure how to do that after an insert.


http://support.microsoft.com/kb/221931/EN-US/

What tool are you using? With ADODB recordsets, you can fetch the
"absolutePosition" property, save it, do a Requery to update the recordset,
then set absolutePosition to the value you saved. Now, you can read the
fields of your new record, including the autonumber.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Feb 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.