How do I retrieve the ID in Access?

Results 1 to 2 of 2

Thread: How do I retrieve the ID in Access?

  1. #1
    Rob Guest

    Default How do I retrieve the ID in Access?

    How do I get the ID in Access?<BR><BR>I am adding a row in Access with the following code. In the database, there is an ID field that creates an AutoNumber. How can I display the generated AutoNumber right after I add the record?<BR><BR>&#039Add a new record...<BR>objRS.AddNew<BR><BR>&#039Iterate through the fields of the table...<BR>Dim fld<BR>For Each fld in objRS.Fields<BR> &#039If a value for the column name was passed in,<BR> &#039set the column name equal to the value passed through the form...<BR> if Len(Request(fld.Name)) &#062; 0 then<BR> fld.Value = Request(fld.Name)<BR> end if<BR>Next<BR><BR>objRS.Update<BR><BR><BR>&#039 I want to display the ID field value that is was just generated????<BR>Response.Write ?????<BR><BR><BR>Thanks.<BR><BR>Rob

  2. #2 Guest

    Default RE: How do I retrieve the ID in Access?

    The new value for the ID will be available as soon as you execute the command, objRS.Update. If this command is successful, the cursor will be located on the record you just added so you can do something like:<BR><BR>Response.Write "The new record is : " & objRS("ID")

Posting Permissions

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