Inserting record with Microsoft Access

J

jeffhg582003

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
 
D

daftspaniel

I can't remember the detail right now but look at SELECT @@IDENTITY.

Cheers,
Davy M
 
K

Kelly

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)
 
T

Tim Roberts

jeffhg582003 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top