CondMedian errors

Rhabdo

Registered User.
Local time
Today, 13:49
Joined
Jun 4, 2014
Messages
28
Hi,

I have managed to successfully get the CondMedian funtion to work directly off a table, no problems. However, i have a form into which i can select start & end dates to query a specific time period and subset of the data. I thin try run a new query on this subset with the CondMedian function and i get an error.

I get a runtime error 3061. Too few parameters. Expected 4.

The syntax is exactly the same as the query which runs directly off the table, the only difference is the second query runs off another query. The SQL code of both is posted below.

Somebody please help me :)

WORKING Query
SELECT t_CBC_Data.Parameter, CondMedian("t_CBC_Data","ParValue","Parameter='" & Parameter & "'") AS Expr1
FROM t_Sites INNER JOIN t_CBC_Data ON t_Sites.Site_ID = t_CBC_Data.Site_ID
GROUP BY t_CBC_Data.Parameter;



NOT WORKING Query
SELECT qr_WQ_CBC_Group_MinMaxN.Parameter, CondMedian("qr_WQ_CBC_Group_MinMaxN","ParValue","Parameter='" & Parameter & "'") AS Expr1
FROM qr_WQ_CBC_Group_MinMaxN
GROUP BY qr_WQ_CBC_Group_MinMaxN.Parameter;
 
This is the code i have in the Module. As i said it works fine when i run a query directly off a table, but it will not work when i run it off another query?

Public Function CondMedian(RstName As String, fldName As String, grpName As String)
'This function will calculate the median of a recordset. The field must be a number value.
Dim MedianTemp As Double
Dim RstOrig As Recordset
Set RstOrig = CurrentDb.OpenRecordset(RstName, dbOpenDynaset)
RstOrig.Sort = fldName
RstOrig.Filter = grpName
Dim RstSorted As Recordset
Set RstSorted = RstOrig.OpenRecordset()
If RstSorted.RecordCount Mod 2 = 0 Then
RstSorted.AbsolutePosition = (RstSorted.RecordCount / 2) - 1
MedianTemp = RstSorted.Fields(fldName).Value
RstSorted.MoveNext
MedianTemp = MedianTemp + RstSorted.Fields(fldName).Value
MedianTemp = MedianTemp / 2
Else
RstSorted.AbsolutePosition = (RstSorted.RecordCount - 1) / 2
MedianTemp = RstSorted.Fields(fldName).Value
End If
CondMedian = MedianTemp
End Function
 

Users who are viewing this thread

Back
Top Bottom