Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculating a MEDIAN value -- ERROR message

Status
Not open for further replies.

timbert62

IS-IT--Management
Nov 19, 2001
8
US
any help anyone can give me would be splendid & MUCH appreciated

i am trying to get a bit of code for calculating MEDIAN values to work

i found the basic code on the web & modified slightly

THANKS TO SOMEONE ON THIS FORUM, i was able to get it to work when grouping by YEAR, but when i changed the code to try make it calculate the MEDIAN of a recordset grouped by a TEXT field [PROP_ADD2], i get an error message =

" Runtime Error '3061':
Too few parameters. Expected 4 "

here is the code i have right now, (with the RED part being what is highlighted in the debug window)

Function MedianProp(tName$, fldName$, Prop$) As String

Dim MedianDB As Database
Dim ssMedian As Recordset
Dim RCount, i, x, y, OffSet As Integer

Dim EvalProp As String

Set MedianDB = CurrentDb()
EvalProp = Prop$
Set ssMedian = MedianDB.OpenRecordset("SELECT [" & fldName$ & "] FROM [" & tName$ & "] WHERE ([PROP_ADD2]=[" & EvalProp & "]) ORDER BY [" & fldName$ & "]")

ssMedian.MoveLast
RCount = ssMedian.RecordCount
x = RCount Mod 2
If x <> 0 Then
OffSet = ((RCount + 1) / 2) - 2
For i = 0 To OffSet%
ssMedian.MovePrevious
Next i
MedianProp = ssMedian(fldName$)
Else
OffSet = (RCount / 2) - 2
For i = 0 To OffSet
ssMedian.MovePrevious
Next i
x = ssMedian(fldName$)
ssMedian.MovePrevious
y = ssMedian(fldName$)
MedianProp = (x + y) / 2
End If
ssMedian.Close
MedianDB.Close
End Function


thanks to anyone who can help me figure out what i'm missing

tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top