Adding Records to Tables with AutoIncrement Fields
Written by Eric Smith, Northstar Computer Systems LLC
Ever have a table that has an autoincrement (AutoNumber in Access, for instance) field and not sure how to add a record to the field? If you try to put a value into the field, you'll get an error. The solution? Don't put a value into it. If you're using an ADO Recordset inserting into a table, you can store the rest of the fields like normal and then do an Update. The database will add your autoincremented number, and you'll be able to get the value immediately after you call the Update method on the ADO Recordset.
The same thing goes for SQL statements. Don't list the automatically supplied field in the list of fields you supply in the INSERT statement and the database will automatically plug the automatic value in.
Keywords: [
Active Data Objects
]
Publication Date: 2/10/2001, Last Update: 2/12/2010
|