Julie Reardon-Taylor
prosoft6 at hotmail.com
Wed Apr 12 07:50:20 CDT 2006
Okay. Still desperately struggling with this. All I want to do now is
dump the 80% of the data into a temp table.
The code below was furnished by Mark Matte.........or most of it anyway.
Instead of getting the mean, all I want to do is strip out the top 10% and
the bottom 10%, then put the remaining records in a table.
This code does insert the records into a temp table, but it inserts all of
the records. I guess I'm not really clear on which portion of Mark's code
actually drops the top 10% and the bottom 10%.
Please help!
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!id
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
Set Rst = db.OpenRecordset("tblTempData", dbOpenDynaset)
Rst.AddNew
Rst!CMonth = MyRst!CMonth
Rst!profile = MyRst!profile
Rst!Unit = MyRst!Unit
Rst.Update
MyRst.MoveNext
Loop
'MsgBox "The TRIMMEAN for " & GroupName & "is " & ListSum / Div
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