Return autonumber value

Results 1 to 3 of 3

Thread: Return autonumber value

  1. #1
    Nancy S. Guest

    Default Return autonumber value

    I have written code to add new records to an Access database. One of the fields in the database is an autonumber field. I would like to return the value, but cannot seem to make it work. Here is my sample code:<BR><BR>Set rsRequest = Server.CreateObject("ADODB.Recordset")<BR>rsReques t.Open "RequestInfo", strConnect, adOpenForwardOnly, adLockOptimistic, adCmdTable<BR>rsRequest.AddNew<BR>rsRequest("UserN ame") = Request.Form("UserName")<BR>rsRequest("PhoneNumber ") = Request.Form("PhoneNumber")<BR>rsRequest.Update<BR ><BR>I can return the other fields with Response.Write rsRequest("UserName"). I just can&#039t get that to work for my autonumber field.<BR><BR>Does anyone have a solution?

  2. #2
    Join Date
    Dec 1969

    Default RE: Return autonumber value

    Nancy-<BR>A quick and dirty way to do it would be to use a simple counter, embedded in a DO WHILE loop such as the following:<BR><BR>dim X &#039counter variable<BR><BR>&#039put the following code in after your DB.Open<BR>X = 1<BR>rsRequest.MoveFirst<BR>Do While Not rsRequest.EOF<BR> Response.Write X &#039this would substitute for the autonumber<BR> Response.Write rsRequest("Username") &#039(and any other fields) <BR> X = X + 1<BR> rsRequest.MoveNext<BR>Loop<BR><BR><BR>Hope this helps. If not - email me at<BR><BR>

  3. #3
    Sandeep Sawhney Guest

    Default RE: Return autonumber value

    Hi<BR><BR>rsRequest.Update<BR>&#039after this command put this there<BR><BR>autocountervalue = rst("Auto_counter_field_name")<BR><BR>Regards<BR>s andyX

Posting Permissions

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