Retrieving ID Field after insert into an Access database 'Create the Connection object set conn = server.createobject("adodb.connection") conn.open strconn
'Create the recordset object set rs = server.createobject("adodb.recordset") 'This statement opens the table so we can add a record notice the addnew 'The 2, 2 is how the table is opened there are many ways it can be opened rs.open "tblAdoAdd", conn, 2, 2
'Use the addnew method of the recordset object to add a record rs.addnew
'Set the table column = to my input text box from my form rs("FirstName") = request("FirstName") rs("LastName") = request("LastName") rs("FavoriteColor") = request("FavoriteColor") rs.update
'I do a movelast here to get the ID that is automatically generated 'I also set the value to a local variable so I can write out to the database rs.movelast strID = rs("ID") rs.close Set rs = nothing conn.close Set conn = nothing |