Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting and Selecting (Autonumber in Access)

Status
Not open for further replies.

savok

Technical User
Jan 11, 2001
303
AT
After I insert new info into an Access table that uses Autonumber, a new Autonumber is assigned. How do I select (find out) that Autonumber while inserting?

In example I insert the info from a few text boxes into the table and its saved, but then i change the info in the text boxes and want to update the table, how do i know the autonumber in order to update the record?

thank you.
 
If you're using ADO to for the Access database, you should be able to reference that field after the update.

RecSet.Update
NewNumber = RecSet.Fields(&quot;<ColumnName>&quot;)

where <ColumnName> is the name of the Auto-Number field. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
here is how i insert the data, what do i do to set intAuto to the new Autonumber? thanks


Dim intAuto as Integer
Set DBComm = New ADODB.Command
DBComm.ActiveConnection = DBConn
DBComm.CommandText = &quot;Insert into Table (Name) values('&quot; & txtName & &quot;',) &quot;
DBComm.CommandType = adCmdText
DBComm.Execute
 
I usually use the RecordSet to add the record.

Dim RecSet as New ADODB.RecordSet

<Connect and Open the RecSet>

RecSet.AddNew
RecSet.Fields(&quot;Fielname1&quot;) = Value1
RecSet.Fields(&quot;Fielname2&quot;) = Value2
...
RecSet.Update
NewNum = RecSet.Fields(&quot;AutoNumberField&quot;) Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top