A question on Looping. There are 3 variables feeding this page, Date3, date4, and facility. Now, facility is a range of facilities, not just one. Date3 and Date 4 create a range of dates in the SQL Query. Currently the output of this page goes to excel as you can see by the “Response.ContentType” and the equations near the end. This writes the formal name of the facility, then all the records for that facility, totals them, etc. then moves to the next facility. You end up with lines like date1, next line, date2, etc. Heres the problem. That is for one facility only. On this specific page, the facility variable is set as a range of facilities in one district. So you select district1 and it contains, say 5 facilities. What I need to do, is summarize all this data by district not indivual facility(Multiple district selections will take place) you will see a variable for private, well, I need my loop to output all the data for all facilities in district1 with the first date in the array on the first line, so, facility1 value for private on first date selected + facility 2 value for private on first date selected, and so on for all records within this district, with matching dates to the date range selected. Then move to the next district if selected. Bill Wilkinson helped me out on this previously setting up the facility loop for a different section of this app, so credits to him.<BR><BR>In summary, the loop in the code below, all needs to be summarized into one output for all facilities in that district, then a loop outside of that needs to move to the next district. <BR><BR>As opposed to looping at the facility level. I just have no Idea how to write that loop. Help is always appreciated.<BR><BR>Thanks,<BR>Steve<BR><BR>< %<BR>response.ContentType="application/vnd.ms-excel"<BR>%><BR><%<BR>Dim selFacility<BR>Dim Date1<BR>Dim Date2<BR>selFacility = Request("facility")<BR>Date1 = Request("date3")<BR>Date2 = Request("date4")<BR><BR>Set RS = Server.CreateObject("ADODB.Recordset")<BR>RS.Activ eConnection = MM_PKMed_STRING<BR>RS.Source = "SELECT WKLYCensus_TBL.strDate, WKLYCensus_TBL.Private, WKLYCensus_TBL.Medicaid, WKLYCensus_TBL.Medicare, WKLYCensus_TBL.Veterans, WKLYCensus_TBL.Hospice, WKLYCensus_TBL.Other, WKLYCensus_TBL.Medicaid_Hospice, WKLYCensus_TBL.FacilityID, WKLYCensus_TBL.DistrictID, WKLYCensus_TBL.Totals, WKLYCensus_TBL.key, Authentication_TBL.FormalName, Authentication_TBL.Buget_Private, Authentication_TBL.Buget_Medicaid, Authentication_TBL.Buget_Medicare, Authentication_TBL.Buget_Veterans, Authentication_TBL.Buget_Hospice, Authentication_TBL.Buget_Other, Authentication_TBL.Budget_MedicaidHospice FROM (WKLYCensus_TBL LEFT JOIN Authentication_TBL ON WKLYCensus_TBL.FacilityID=Authentication_TBL.Facil ityID) WHERE WKLYCensus_TBL.FacilityID IN (" & selFacility & ") And strDate Between #" & Date1 & "# AND #" & Date2 & "# ORDER BY WKLYCensus_TBL.FacilityID ASC, WKLYCensus_TBL.strDate ASC"<BR>RS.Open()<BR>%><BR><BR><BR><BR>< %<BR>priorFacility = ""<BR>privatetotal = 0<BR>medicaidtotal = 0<BR>medicaretotal = 0<BR>veteranstotal = 0<BR>hospicetotal = 0<BR>othertotal = 0<BR>medicaid_hospicetotal = 0<BR>totaltotal = 0<BR>RSgrandtotal = 0<BR>BudgetPrivate = 0<BR>BudgetMedicaid = 0<BR>BudgetMedicare = 0<BR>BudgetVeterans = 0<BR>BudgetHospice = 0<BR>BudgetOther = 0<BR>BudgetMedicaidHospice = 0<BR><BR>Do Until RS.EOF<BR> curFacility = RS("FacilityID")<BR> If curFacility <> priorFacility Then<BR> If priorFacility <> "" Then<BR> End If<BR> Response.Write "<TR>" & "<TD><Strong>" & RS("FormalName") & "</Strong></TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR>"<BR> priorFacility = curFacility<BR> BudgetPrivate = RS("Buget_Private")<BR> BudgetMedicaid = RS("Buget_Medicaid")<BR> BudgetMedicare = RS("Buget_Medicare")<BR> BudgetVeterans = RS("Buget_Veterans")<BR> BudgetHospice = RS("Buget_Hospice")<BR> BudgetOther = RS("Buget_Other")<BR> BudgetMedicaidHospice = RS("Budget_MedicaidHospice")<BR> RS_total=0<BR> <BR> End If<BR> Response.Write "<TR>" &"<TD> </TD><TD>" & RS("strDate") & "</TD><TD>" & RS("Private") & "</TD><TD>" & RS("Medicaid") & "</TD><TD>" & RS("Medicare") & "</TD><TD>" & RS("Veterans") & "</TD><TD>" & RS("Hospice") & "</TD><TD>" & RS("Other") & "</TD><TD>" & RS("Medicaid_Hospice") & "</TD><TD>" & RS("Totals") & "</TD></TR>"<BR> RS_total = RS_total + 1<BR> privatetotal = privatetotal + RS("Private")<BR> medicaidtotal = medicaidtotal + RS("Medicaid")<BR> medicaretotal = medicaretotal + RS("Medicare")<BR> veteranstotal = veteranstotal + RS("Veterans")<BR> hospicetotal = hospicetotal + RS("Hospice")<BR> othertotal = othertotal + RS("Other")<BR> medicaid_hospicetotal = medicaid_hospicetotal + RS("Medicaid_Hospice")<BR> totaltotal = totaltotal + RS("Totals")<BR> RSgrandtotal = RSgrandtotal + 1<BR> RS.MoveNext<BR> doTotal = True <BR> If Not RS.EOF Then If RS("FacilityID") = curFacility Then doTotal = False <BR> If doTotal Then <BR> Response.Write "<tr><td height=""19"" bgcolor=""#CCCCCC"">Budget</td><td height=""19"" bgcolor=""#CCCCCC""> </td><td height=""19"" bgcolor=""#CCCCCC"">" & BudgetPrivate & "</td><td height=""19"" bgcolor=""#CCCCCC"">" & BudgetMedicaid & "</td><td height=""19"" bgcolor=""#CCCCCC"">" & BudgetMedicare & "</td><td height=""19"" bgcolor=""#CCCCCC"">" & BudgetVeterans & "</td><td height=""19"" bgcolor=""#CCCCCC"">" & BudgetHospice & "</td><td height=""19"" bgcolor=""#CCCCCC"">" & BudgetOther & "</td><td height=""19"" bgcolor=""#CCCCCC"">" & BudgetMedicaidHospice & "</td><td height=""19"" bgcolor=""#CCCCCC""> </td></tr>" <BR> Response.Write "<TR><TD bgcolor=""#CCCCCC"">Totals: from <BR><font size=""1"" face=""Arial, Helvetica, sans-serif"">" & Date1 & " to " & Date2 & "</font></TD><TD bgcolor=""#CCCCCC""></TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-2,,-" & RS_total & ")),2)</TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-2,,-" & RS_total & ")),2)</TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-2,,-" & RS_total & ")),2)</TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-2,,-" & RS_total & ")),2)</TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-2,,-" & RS_total & ")),2)</TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-2,,-" & RS_total & ")),2)</TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-2,,-" & RS_total & ")),2)</TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-2,,-" & RS_total & ")),2)</TD></TR><TR><TD bgcolor=""#CCCCCC"">Daily Averages: from <BR><font size=""1"" face=""Arial, Helvetica, sans-serif"">" & Date1 & " to " & Date2 & "</font></TD><TD bgcolor=""#CCCCCC""> </TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-4,,-" & RS_total & "))/" & RS_total & ",2)</TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-4,,-" & RS_total & "))/" & RS_total & ",2)</TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-4,,-" & RS_total & "))/" & RS_total & ",2)</TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-4,,-" & RS_total & "))/" & RS_total & ",2)</TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-4,,-" & RS_total & "))/" & RS_total & ",2)</TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-4,,-" & RS_total & "))/" & RS_total & ",2)</TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-4,,-" & RS_total & "))/" & RS_total & ",2)</TD><TD bgcolor=""#CCCCCC"">=ROUND(SUM(OFFSET(INDIREC T(ADDRESS(ROW(),COLUMN())),-4,,-" & RS_total & "))/" & RS_total & ",2)</TD></TR><TR><TD height=""100""> </TD></TR><TR><TD bgcolor=""#CCCCCC"">Facility</TD><TD bgcolor=""#CCCCCC"">Date</TD><TD bgcolor=""#CCCCCC"">Private</TD><TD bgcolor=""#CCCCCC"">Medicaid</TD><TD bgcolor=""#CCCCCC"">Medicare</TD><TD bgcolor=""#CCCCCC"">Veterans</TD><TD bgcolor=""#CCCCCC"">Hospice</TD><TD bgcolor=""#CCCCCC"">Other</TD><TD bgcolor=""#CCCCCC"">Medicaid/Hospice</TD><TD bgcolor=""#CCCCCC"">Totals</TD></TR>"<BR> <BR> End If <BR><BR>Loop<BR>Response.Write "<TR><TD height=""50""></TD></TR><TR><TD><strong&# 062;Grand Totals</strong></TD></TR><TR><TD><strong&# 062;Summary</strong></TD><TD><font size=""1"" face=""Arial, Helvetica, sans-serif"">" & Date1 & " to " & Date2 & "</font></TD><TD>" & privatetotal & "</TD><TD>" & medicaidtotal & "</TD><TD>" & medicaretotal & "</TD><TD>" & veteranstotal & "</TD><TD>" & hospicetotal & "</TD><TD>" & othertotal & "</TD><TD>" & medicaid_hospicetotal & "</TD><TD>" & totaltotal & "</TD></TR><TR><TD><strong&# 062;Daily Averages</strong></TD><TD><font size=""1"" face=""Arial, Helvetica, sans-serif"">" & Date1 & " to " & Date2 & "</font></TD><TD>=ROUND(" & privatetotal/RSgrandtotal & ",2)</TD><TD>=ROUND(" & medicaidtotal/RSgrandtotal & ",2)</TD><TD>=ROUND(" & medicaretotal/RSgrandtotal & ",2)</TD><TD>=ROUND(" & veteranstotal/RSgrandtotal & ",2)</TD><TD>=ROUND(" & hospicetotal/RSgrandtotal & ",2)</TD><TD>=ROUND(" & othertotal/RSgrandtotal & ",2)</TD><TD>=ROUND(" & medicaid_hospicetotal/RSgrandtotal & ",2)</TD><TD>=ROUND(" & totaltotal/RSgrandtotal & ",2)</TD></TR>"<BR><BR>Response.Write "</table>"<BR>%><BR><% End If %><BR><% If RS.EOF And RS.BOF Then %><BR><p>No results found</p><BR>