Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Posts
    6

    Unanswered: Add Total Through Loop?

    Hello.

    I am using ASP and MS Access for this.

    I have a form where a user will enter in some order information, then a list of part numbers, quantities, and other attributes for the part number.

    After the user clicks submit the page below adds the basic order information to a table called *IRR*. Then it loops through all of the specific parts and adds them to the *ORDERS* table. Each part is a new record and a field called IRRID matches it to the associated order in the *IRR* table.

    Anyhow... My question is how can I loop through the information entered into the *POQTY* and *DamagedQTY* fields below, add everything in the POQTYi fields together and place the total into a field in the *IRR* table called POQTY. I also need to get the total for DamagedQTY and place that into a field in the *IRR* table called DamagedQTY.

    Code:
    <%
    
    
    'Create an ADO connection object
    Set adoCon = Server.CreateObject("ADODB.Connection")
    
    'Set an active connection to the Connection object using a DSN-less connection
    adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("irr.mdb")
    
    
    
    Set irrRS = Server.CreateObject("ADODB.Recordset")
    irrRS.Open "SELECT * FROM irr WHERE 1=0", adocon, 3, 3
    irrRS.AddNew
    
    
    
    'Add a new record to the recordset
    irrRS.Fields("Receiver") = Request.Form("Receiver")
    irrRS.Fields("BOLTracking") = Request.Form("BOLTracking")
    irrRS.Fields("Carrier") = Request.Form("Carrier")
    irrRS.Fields("Notes") = Request.Form("Notes")
    irrRS.Fields("Location") = Request.Form("Location")
    irrRS.Fields("Date") = Request.Form("Date")
    irrRS.Fields("Day") = Request.Form("Day")
    irrRS.Fields("Year") = Request.Form("Year")
    irrRS.Fields("IssueType") = Request.Form("IssueType")
    irrRS.Fields("DescrepType") = Request.Form("DescrepType")
    irrRS.Fields("StorageLoc") = Request.Form("StorageLoc")
    irrRS.Fields("Month") = Request.Form("Month")
    irrRS.Fields("PO") = Request.Form("PO")
    irrRS.Fields("Order") = Request.Form("Order")
    irrRS.Fields("USDIR") = Request.Form("USDIR")
    irrRS.Fields("RMA") = Request.Form("RMA")
    
    
    
    irrRS.Update
    newID = irrRS("ID") ' Captures ID into variable
    Issue = irrRS("IssueType")
    
    
    
    ' okay, we have a product id...so create a record in orders table:
    Set ordRS = Server.CreateObject("ADODB.Recordset")
    ordRS.Open "SELECT * FROM orders WHERE 1=0", adocon, 3, 3
    
    For i = 1 To 99999
        VendorPart = Trim(Request("VendorPart" & i))
        If VendorPart = "" Then Exit For ' no more to get
    
        ordRS.AddNew ' add a new record to put stuff into
        ordRS("IRRID") = newID ' adds the ID variable into orders table
        ordRS("IssueType") = Issue ' adds the Issue variable into orders table
        ordRS("VendorPart") = VendorPart ' we already had this value
        ' add other fields for this record, to match the "i":
        ordRS("DamagedQTY") = Request("DamagedQTY" & i) 
    ordRS("PhysicalQTY") = Request("PhysicalQTY" & i) 
    ordRS("PackQTY") = Request("PackQTY" & i) 
    ordRS("OverQTY") = Request("OverQTY" & i) 
    ordRS("ShortQTY") = Request("ShortQTY" & i) 
    ordRS("POQTY") = Request("POQTY" & i) 
    ordRS("Serials") = Request("Serials" & i) 
    ordRS("InternalPart") = Request("InternalPart" & i)
    
        ordRS.Update
    Next
    
    
    
    
    
    irrRS.Close
    ordRS.Close
    
    
    
    
    'Redirect to the details page using the new ID
    Response.Redirect (Trim(Issue) & "verifydetails.asp?ID=" & newID)
    %>
    Any help?

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    So something like this???

    Code:
    Dim totPOQTY
    Dim totDamQty
    
    totPOQTY = 0
    totDamQty = 0
    
    For i = 1 To 99999
        VendorPart = Trim(Request("VendorPart" & i))
        If VendorPart = "" Then Exit For ' no more to get
    
        ordRS.AddNew ' add a new record to put stuff into
        ordRS("IRRID") = newID ' adds the ID variable into orders table
        ordRS("IssueType") = Issue ' adds the Issue variable into orders table
        ordRS("VendorPart") = VendorPart ' we already had this value
        ' add other fields for this record, to match the "i":
        ordRS("DamagedQTY") = Request("DamagedQTY" & i) 
    
        totDamQty = totDamQty + CInt(Request("DamagedQTY" & i))
    
        ordRS("PhysicalQTY") = Request("PhysicalQTY" & i) 
        ordRS("PackQTY") = Request("PackQTY" & i) 
        ordRS("OverQTY") = Request("OverQTY" & i) 
        ordRS("ShortQTY") = Request("ShortQTY" & i) 
        ordRS("POQTY") = Request("POQTY" & i) 
    
        totPOQTY = totPOQTY  + CInt(Request("POQTY" & i))
    
        ordRS("Serials") = Request("Serials" & i) 
        ordRS("InternalPart") = Request("InternalPart" & i)
    
        ordRS.Update
    Next
    
    Dim updateSQL
    updateSQL = "Update irr set TotalPOQTY = " + totPOQTY  + ", TotalDamageQty="+ totDamQty + " where irr.ID = " + newID
    
    adocon.Execute(updateSQL)
    I haven't played with ASP for a while but it should be close enough for you to get it working.

Posting Permissions

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