How to get the value of an Auto ID from a new reco

Results 1 to 3 of 3

Thread: How to get the value of an Auto ID from a new reco

  1. #1
    Rhese Guest

    Default How to get the value of an Auto ID from a new reco

    My question is regarding how to get the value of a field that is automatically generated when adding a new record to SQL. For example, I have a Table: tblJobPostings and I have my form that uses .addnew to add the new job posting fields to the record. When that new record is created, it automatically generates the "JobID". I then need to immediately pull the value of the JobID back out of the record set so that I can enter it&#039s value into another new record for another table. My following code used to work, but I&#039m not sure when it stoped working.. possibly when I upsized from Access to SQL??<BR><BR>The below example used to work... the line after the .update would get the value of the ID for the record that was just created... doesn&#039t seem to be working now though. And yes.. the field "JobID" is valid in that database.<BR><BR>Email me directly at:<BR><BR>Thanks in advance!!<BR><BR>&#039 OPEN MAJEC DSN<BR>&#039 ================================================== =========<BR> %&#062;<BR> &#060;!--#include file="OPEN_DSN_MAJEC.ASP"--&#062;<BR> &#060;%<BR><BR>&#039 ADD NEW JOB TO THE DATABASE<BR>&#039 ================================================== =========<BR> Set cmdMajecAdd = Server.CreateObject("ADODB.Command")<BR> Set rsMajecAdd = Server.CreateObject("ADODB.Recordset")<BR> cmdMajecAdd.CommandText = "tblJobPostings"<BR> cmdMajecAdd.CommandType = 2<BR> Set cmdMajecAdd.ActiveConnection = dbMajec<BR> rsMajecAdd.Open cmdMajecAdd, , 1, 3<BR> <BR> rsMajecAdd.Addnew<BR> <BR> rsMajecAdd ("MemberID") = Session("MajecMemberID")<BR> rsMajecAdd ("DatePosted") = Date()<BR> rsMajecAdd ("DateModified") = Date()<BR> rsMajecAdd ("Active") = "Active"<BR> rsMajecAdd ("Title") = tmpTitle<BR> rsMajecAdd ("Description") = tmpDescription<BR> rsMajecAdd ("Type") = tmpType<BR> rsMajecAdd ("Title") = tmpTitle<BR> rsMajecAdd ("Location") = tmpLocation<BR> rsMajecAdd ("SalaryType") = tmpSalaryType<BR> etc..<BR><BR> rsMajecAdd.Update<BR> <BR> tmpMajecJobID = rsMajecAdd("JobID") &#060;-- LINE IN QUESTION?????<BR><BR> If (Err.Number &#060;&#062; 0) Then<BR> rsMajecAdd.CancelUpdate<BR> End If<BR> <BR>&#039 CLOSE MAJEC RECORDSET & DATABASE CONNECTIONS<BR>&#039 ================================================== =========<BR> rsMajecAdd.Close<BR> dbMajec.Close

  2. #2

    Default RE: How to get the value of an Auto ID from a new

    Check this out. Step by step instructions on how to do this. Both in SQL and Access.<BR><BR><BR>HTH,<BR>DRUG_DEALER

  3. #3
    Rhese Guest

    Default But how do you do it in SQL?

    Ok.. thanks for the reply.. I looked at your URL, but it only shows how to do it in Access using the method I&#039m already doing. I didn&#039t see the example of how to do it using SQL server. Any suggestions?<BR><BR>Thanks!

Posting Permissions

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