How can I return the autonumber...

Results 1 to 3 of 3

Thread: How can I return the autonumber...

  1. #1
    Join Date
    Dec 1969

    Default How can I return the autonumber...

    How can I return the autonumber assigned to a new record inserted into an Access db?

  2. #2
    Join Date
    Dec 1969

    Default ASPFAQs.

    Upper right hand corner of this page. One of the Database categories.

  3. #3
    Join Date
    Dec 1969

    Default Here it is:

    &#039;Open the connection<BR>Set MyConn = Server.CreateObject("ADODB.Connection")<BR>MyConn. Open "[your connection]"<BR><BR>&#039;Create a Recordset object<BR>Set objRecordset = Server.CreateObject("ADODB.Recordset")<BR>objRecor dset.Open "[your table]", MyConn, adOpenKeyset, adLockOptimistic, adCmdTable<BR><BR>&#039;Start adding the records<BR>objRecordset.AddNew<BR>objRecordset("[Name of field 1") = [your content]<BR>objRecordset("[Name of field 2") = [your content]<BR><BR>&#039;and so forth until last field, then...<BR><BR>objRecordset.Update<BR><BR>iRecordA dded=objRecordset("ID")<BR><BR>&#039;now you have a variable with the correct AutoNumber in it (in this example, the field was called "ID").<BR><BR>&#039;Close Recordset and connection<BR>objRecordset.Close<BR>set objRecordset = nothing<BR><BR>MyConn.Close<BR>set MyConn = nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts