One addnew creates two records in database.

Results 1 to 4 of 4

Thread: One addnew creates two records in database.

  1. #1
    Join Date
    Dec 1969

    Default One addnew creates two records in database.

    I&#039;m using the code below to receive posted data from an HTML form on the same site and write it to an Access database. It creates a new record with no problem. But it also adds another record, not with the information coming from request.form but just the information that is assigned to variables. My primary key is incident_id and I want to create a sequential number for each record. I don&#039;t want to use the Access AutoNumber type for this. So I figure that my recordset which is "Order By incident_id" will have the last record as the highest number and I just add one to it to create a new incident_id. This works fine. It just creates that second record too. If I just explicitly assign the incident_id without using anything from the objRec recordset it works fine too and does not create an additional record.<BR><BR>I&#039;ve done this before without any problem and I cannot figure out what&#039;s wrong. I&#039;ve been hours messing with this. For some reason it&#039;s creating two records in the database. Thanks for any help! <BR><BR><BR>&#060;% Option Explicit %&#062;<BR>&#060;!--#include file=""--&#062;<BR><BR>&#060;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"&#062;<BR>&#060;HTML&#062;<BR>&#060;HEAD&#062;< BR>&#060;TITLE&#062;Form Post Test Page&#060;/TITLE&#062;<BR><BR>&#060;/HEAD&#062;<BR><BR>&#060;BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" VLINK="#800000" ALINK="#FF00FF"&#062;<BR><BR>&#060;%<BR><BR>dim strUser,dteSubmissionDate,dteSubmissionTime,strInc identStatus<BR>dim objConn,objRec,strSQL,intIncidentID<BR><BR>strUser = "TestUser"<BR>dteSubmissionDate = date<BR>dteSubmissionTime = time<BR>strIncidentStatus = "Open"<BR><BR>strSQL = "Select * From tbl_Incidents Order By incident_id desc"<BR><BR>Set objConn = Server.CreateObject("ADODB.Connection")<BR>Set objRec = Server.CreateObject("ADODB.RecordSet")<BR>objConn. Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("cchelpnet.mdb"))<BR>objRec.Open strSQL, objConn,adopendynamic,adlockoptimistic<BR><BR>objR ec.movelast<BR><BR>intIncidentID = objRec("incident_id")<BR>intIncidentID = intIncidentID + 1<BR><BR>objRec.addnew<BR>objRec("incident_id") = intIncidentID<BR>objRec("company_name") = request.form("company_name")<BR>objRec("contact_na me") = request.form("contact_name")<BR>objRec("contact_ph one") = request.form("contact_phone")<BR>objRec("contact_e mail") = request.form("contact_email")<BR>objRec("incident_ time") = request.form("incident_time")<BR>objRec("incident_ date") = request.form("incident_date")<BR>objRec("participa nt_phone") = request.form("participant_phone")<BR>objRec("diale d_access_number") = request.form("dialed_access_number")<BR>objRec("in cident_priority") = request.form("incident_priority")<BR>objRec("confe rence_id") = request.form("conference_id")<BR>objRec("customer_ acct_number") = request.form("customer_acct_number")<BR>objRec("br idge_id") = request.form("bridge_id")<BR>objRec("incident_desc ription") = request.form("incidentdesc")<BR>objRec("submission _by") = strUser<BR>objRec("submission_date") = dteSubmissionDate<BR>objRec("submission_time") = dteSubmissionTime<BR>objRec("incident_status") = strIncidentStatus<BR>objRec.update<BR><BR>objRec.C lose<BR>objConn.Close<BR>Set objRec = Nothing<BR>Set objConn = Nothing<BR><BR>%&#062;<BR><BR>&#060;/BODY&#062;<BR>&#060;/HTML&#062;<BR>

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default BIG mistake

    &#062;Select * From tbl_Incidents Order By incident_id desc"<BR>will give you the LAST record FIRST<BR><BR>&#062;objRec.movelast<BR>will take you to the last record...this will nto whave the first ID<BR><BR>&#062;intIncidentID = intIncidentID + 1<BR>will give you the FIRST id + 1<BR><BR>lose the .movelast<BR><BR>secondly why select ALL the records from the Db to get the last inserted ID<BR><BR>use Max(incident_id) + 1 to get the new Id you need to insert this recordset value into the Db for your new record<BR><BR><BR>

  3. #3
    New ASP Guest

    Default try this pls

    objRec.addnew<BR>:<BR>1st rec<BR>:<BR>objRec.addnew<BR>:<BR>2nd rec<BR>:<BR>objRec.UpdateBatch &#060;---<BR>:<BR><BR><BR><BR><BR>

  4. #4
    Join Date
    Dec 1969

    Default RE: One addnew creates two records in database.


Posting Permissions

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