Get the last record id in a table and then.....

Results 1 to 2 of 2

Thread: Get the last record id in a table and then.....

  1. #1
    Join Date
    Dec 1969

    Default Get the last record id in a table and then.....

    Ok, I am working on a script that allows a user to add a order to a database and then it emails a copy of the order to the person who placed the order and then emails the admin a copy of the order. The If&#039;s are to check to see if they put anything in each product quanity textbox and if so it exe&#039;s the code.<BR><BR>Bascially what I need todo is get the last record set ID from the table called "tblTotPrice" then store that # in a variable and then add 1 to that varible so that I can store this number in my table "tblOrders" as the order ID for "tblOrders".<BR><BR>I hope i gave a good example. Below is the ERROR and Code im getting. And in advance thanks for any help.<BR>Darrell<BR>-------------<BR>Error:<BR>-----<BR>Microsoft JET Database Engine error &#039;80040e14&#039; <BR><BR>Number of query values and destination fields are not the same. <BR><BR>/dev/gq/sendmail.asp, line 51 <BR><BR>------<BR>Code<BR>------<BR>objRS = objConn.Execute("SELECT Max(ID) FROM tblTotPrice")<BR>newID = objRS(0)<BR><BR><BR><BR>Response.Write newID<BR>If Request.Form("QTY_1A") &#060;&#062; "" Then<BR> QTY_1A = Request.Form("QTY_1A")<BR> QTY_1A_Final = QTY_1A * 5.90<BR> prod1a_cost = Request.Form("prod1a_cost")<BR> prod1a_num = Request.Form("prod1a_num")<BR> QTY_TOT = QTY_TOT + QTY_1A_Final<BR> ODate = Date()<BR> Approved = "No"<BR> objConn.Execute "INSERT into tblOrders (Product_ID, Item_Price, Total_Item_Price, QTY, Order_Date, Approved, Order_ID) VALUES (&#039;" & newID & "&#039;,&#039;" & prod1a_num & "&#039;,&#039;" & prod1a_cost & "&#039;,&#039;" & qty_1A_Final & "&#039;,&#039;" & QTY_1A & "&#039;,&#039;" & ODate & "&#039;,&#039;" & Approved & "&#039;,&#039;" & newID & "&#039;)"<BR> <BR><BR> Jmail.AppendText "Product Name: " & product1 & vbcrlf<BR> Jmail.AppendText "Stock Number: " & prod1a_num & vbcrlf<BR> Jmail.AppendText "Price Each: " & prod1a_cost & vbcrlf<BR> Jmail.AppendText "Quanity: " & QTY_1A & vbcrlf<BR> Jmail.AppendText "Total Item Price: " & FORMATCURRENCY(QTY_1A_Final) & vbcrlf<BR> Jmail.AppendText "------------------" & vbcrlf & vbcrlf<BR><BR>End If

  2. #2
    Heaven's Martini Guest

    Default RE: Get the last record id in a table and then....

    Well<BR><BR>i count 7 column names and 8 values.<BR><BR>then in your second sql statement<BR>why not do <BR>VALUES (&#039;" & newID+1 & "&#039;,...<BR><BR>hmmm.

Posting Permissions

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