Autonumber returned

Results 1 to 3 of 3

Thread: Autonumber returned

  1. #1
    Join Date
    Dec 1969

    Default Autonumber returned

    The following is in the Common Database Questions. But the Answer is a dead link.<BR><BR>I need to get the value of an Autonumber field (in MS Access) upon a record insert. How do I do this!?<BR>[Answer] <BR><BR>So I keep looking intill I found the answer and thought it may help someone else, so here is a code that I worked out with the information that I found. I am sure there are easer ways and maybe someone else will come across with one. <BR><BR>&#060;%<BR>Dim objConn<BR>Set objConn = Server.CreateObject("ADODB.Connection")<BR>objConn .ConnectionString= "Driver={Microsoft Access Driver (*.mdb)};" & _ <BR>"DBQ=" & Server.MapPath("db/newbie.mdb")<BR>objConn.Open<BR>&#039;Open Recordset--&#062;<BR>Dim objRS<BR>Set objRS = Server.CreateObject ("ADODB.Recordset")<BR><BR>&#039;Access does not support a cursor engine so a client cursor must be used<BR>objRS.CursorLocation = adUseClient<BR><BR>objRS.Open "tblfriend", objConn, adOpenStatic, adLockOptimistic<BR>&#039;Add new record to database<BR>objRS.AddNew<BR><BR>objRS("strname") = "Tim"<BR>objRS("Alevel") = "40"<BR>objRS("strship") = "Ship"<BR>objRS("Ashield") = "400"<BR>objRS("Sshield") = "400"<BR>objRS("Aarmor") = "800"<BR>objRS("Sarmor") = "800"<BR>objRS("Adrones") = "100"<BR>objRS("Sdrones") = "100"<BR>objRS("hp") = "2"<BR><BR>objRS.Update<BR><BR>&#039;After the update you requery the autonumber field<BR>Response.Write "Requery right after update = " & objRS("number") <BR><BR>objRS.Close<BR>objConn.Close<BR>set objConn = nothing<BR>set objRS = nothing<BR>%&#062;<BR>

  2. #2
    Join Date
    Dec 1969

    Default try again..

    the link works OK from me<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default Yep, that's what the FAQ says...

    The ASPFAQs have sure been having problems lately.<BR><BR>Oh...and there *is* another way, if you prefer using SQL INSERT queries instead of AddNew.<BR><BR>adOpenKeyset works, too. And I *believe* that if you use it you don&#039;t need the adUseClient.<BR><BR>Also, a sneaky trick: Instead of doing this<BR> objRS.Open "tblfriend", objConn, adOpenStatic, adLockOptimistic<BR>which, with a client side cursor, could drag the entire table into ADO memory, you can do this:<BR> objRS.Open "SELECT * FROM tblfriend WHERE 1=0", objConn, adOpenStatic, adLockOptimistic<BR><BR>I *think* that will get the "structure" of the recordset without actually getting any data. But if it doesn&#039;t work, you could always do<BR> objRS.Open "SELECT * FROM tblfriend WHERE number=1", objConn, adOpenStatic, adLockOptimistic<BR>assuming that recored w/ autonumber=1 hasn&#039;t been deleted. All you really care about is getting the right fields with the right types in place; the data you get from the SELECT is irrelevant.<BR><BR>

Posting Permissions

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