Julie Reardon-Taylor
prosoft6 at hotmail.com
Wed Apr 12 09:11:34 CDT 2006
Okay. I think this is now working. Here is the code below: Private Sub Command0_Click() Dim Per Per = 0.2 Dim db As DAO.Database Set db = CurrentDb() Dim GroupRst As DAO.Recordset Set GroupRst = db.OpenRecordset("SELECT tblMonthlyProfile.Profile FROM tblMonthlyProfile GROUP BY tblMonthlyProfile.Profile;", DB_OPEN_DYNASET) Dim GroupName As Field Set GroupName = GroupRst!Profile Do Until GroupRst.EOF Dim MyRst As DAO.Recordset Set MyRst = db.OpenRecordset("SELECT tblMonthlyProfile.id, tblMonthlyProfile.Profile, tblMonthlyProfile.Unit, tblMonthlyProfile.Cmonth FROM tblMonthlyProfile WHERE (((tblMonthlyProfile.Profile) = " & GroupName & ")) ORDER BY tblMonthlyProfile.profile;", DB_OPEN_DYNASET) Dim List As Field Set List = MyRst!CMonth Dim Counter Counter = MyRst.RecordCount Dim Trim Dim MaxTrim Dim Div If InStr(1, Int(Counter * Per) / 2, ".") = 0 Then Trim = Int(Counter * Per) / 2 MaxTrim = Counter - Int(Counter * Per) / 2 + 1 Div = Counter - Int(Counter * Per) Else Trim = (Int(Counter * Per) - 1) / 2 MaxTrim = Counter - (Int(Counter * Per) - 1) / 2 + 1 Div = Counter - Int(Counter * Per) + 1 End If Dim ListSum ListSum = 0 Dim Num Num = 0 Do Until MyRst.EOF Num = Num + 1 If Num > Trim And Num < MaxTrim Then ListSum = ListSum + List Else ListSum = ListSum End If MyRst.MoveNext Loop Set Rst = db.OpenRecordset("tblTempData", dbOpenDynaset) Rst.AddNew Rst!CMonth = (ListSum / Div) Rst!Profile = GroupName Rst!Unit = Div Rst!ID = ListSum Rst.Update GroupRst.MoveNext Loop End Sub Julie Reardon-Taylor PRO-SOFT OF NY, INC. 44 Public Square Suite #5 Watertown, NY 13601 Phone: 315.785.0319 Fax: 315.785.0323 www.pro-soft.net NYS IT Services Contract CMT026A NYS Certified Woman-Owned Business