PDA

View Full Version : Add Total Through Loop?


kennywhite
10-15-2010, 04:07 PM
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.


<%


'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???

Thanks for looking!!!

Old Pedant
10-15-2010, 07:20 PM
Easy peasy.

<%
'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

POQty = 0
DamagedQty = 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)
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

' also accumulate totals:
POQty = POQty + CLNG("0" & Request("POQty" & i) )
DamagedQty = DamagedQty + CLNG("0" & Request("DamagedQTY" & i) )
Next

' update the irr record:
irrRS("POQty") = POQty
irrRS("DamagedQry") = DamagedQTY
irrRS.Update ' update it *again*

irrRS.Close
ordRS.Close

'Redirect to the details page using the new ID
Response.Redirect (Trim(Issue) & "verifydetails.asp?ID=" & newID)
%>

kennywhite
10-15-2010, 07:54 PM
Sweet! That is perfect! Thank you so much.

Just a note in case anyone ever needs to reference this. On the above code, there is a typo here.
irrRS("DamagedQry") = DamagedQTY
Qry instead of QTY.

Again, thank you!

Old Pedant
10-15-2010, 08:06 PM
That's not a typo. You named your Database field wrong!

Just kidding, of course. Hey, I'm a programmer, not a typist. <grin/>