If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Add Total Through Loop?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-15-10, 10:42
kennywhite kennywhite is offline
Registered User
 
Join Date: Feb 2009
Posts: 6
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?
Reply With Quote
  #2 (permalink)  
Old 01-09-11, 16:00
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On