Auto Number question

Results 1 to 4 of 4

Thread: Auto Number question

  1. #1
    cheri Guest

    Default Auto Number question

    On an active server page, when I add a record to a table, is there a way for me to get the new Auto Number before closing the recordset?<BR><BR>Thanks!

  2. #2
    LeeAnnie Guest

    Default RE: Auto Number question

    Of course! Here is an example of what I have done:<BR><BR><BR>Set Cm = Server.CreateObject("ADODB.Recordset")<BR> cntStr = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:pathnamedb1.mdb;"<BR> Cm.Open "YourTable", cntStr, adOpenKeySet, adLockPessimistic, adCmdTable<BR> Cm.AddNew<BR> Cm.Fields("empFirstName")=sql_quote(request("First Name"))<BR> Cm.Fields("empLastName")=sql_quote(request("LastNa me"))<BR> Cm.Fields("empEmailAddress")=request("Email")<BR> Cm.Fields("empWorkPhoneArea")=request("PhoneArea") <BR> Cm.Fields("empWorkPhoneExch")=request("PhoneExch") <BR> Cm.Fields("empWorkPhoneNum")=request("Phone")<BR>C m.Fields("empLastModifiedBy")=session("empID")<BR> Cm.Fields("empLastModifiedOn")=now()<BR> Cm.Update<BR> EmpID = Cm.Fields("empAutoID")<BR> Cm.Close<BR> set Cm=Nothing<BR><BR>The third to the last line of the above code sets the variable, EmpID, to the Autonumber field, empAutoID, in my database.<BR><BR>Hope this helps!

  3. #3
    cheri Guest

    Default RE: Auto Number question

    Thanks, LeeAnnie!!!

  4. #4
    Join Date
    Dec 1969

    Default RE: Auto Number question

    Hi. I had the same question that you answered, but this doesn&#039t work for me. The first three lines of opening the connection and recordset aren&#039t identical to your code, but the other stuff seems to be. I end up with nothing in variable adID. The Autonumber field in my Access database is also called adID.<BR><BR>Am I going crazy? Any help would be very much appreciated. (I&#039ve been trying to solve this one for 4 hours!)<BR><BR><BR><BR>Set myConn = Server.CreateObject ("ADODB.Connection")<BR>myConn.Open "DBQ=" & Server.Mappath("/fpdb/pals.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"<BR><BR>Set rs = Server.CreateObject ("ADODB.Recordset")<BR>rs.Open "profiles", myConn, adOpenKeyset, 3, &H0002<BR><BR>rs.AddNew<BR>rs.Fields("name") = Request.Form("name")<BR>rs.Fields("password") = Request.Form("password1")<BR>rs.Fields("myEmail") = Request.Form("myEmail")<BR>rs.Fields("homepage") = Request.Form("homepage")<BR>rs.Update<BR><BR>adID = rs.Fields("adID")<BR><BR>rs.Close<BR>Set rs = Nothing<BR>myConn.Close<BR>Set myConn = Nothing<BR><BR>Response.Redirect "/confirmation.asp?action=added&ID=" & adID

Posting Permissions

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