Kotartidzo
Technical User
I am trying to calculate the Median value for a field in a grouped report. The wierd thing is it works in my beta-test version but not in my production version. I am assuming I am missing some setting in my production version. I have confirmed my VBA references match in both versions. I am attaching a portion of the module. Any comments would be appreciated.
Public Function Median(TableName As String, FieldName As String, Optional Condition As String = vbNullString)
Dim str As String
Dim rst As DAO.Recordset
Dim n As Long
Dim x As Variant
Dim Centr As Variant
Dim db As Database: Set db = CurrentDb
str = " FROM " & TableName
If vbNullString = Condition Then
Else
str = str & " WHERE " & Condition
End If
'*** the following line of code is where the error keeps comming up. ***
Set rst = db.OpenRecordset("SELECT " & FieldName & str & " ORDER BY " & FieldName, dbOpenForwardOnly, dbReadOnly)
'calculate the number of records in the dataset
n = CurrentDb.OpenRecordset("SELECT COUNT(*)" & str).Fields(0).Value
***** the next line is the call statement in the report
=Median("qWEDnetEcoData","[Lead-timeVariance]")
I get the following error message.
Run time error "3061" Too few parameters. Expected 3.
Public Function Median(TableName As String, FieldName As String, Optional Condition As String = vbNullString)
Dim str As String
Dim rst As DAO.Recordset
Dim n As Long
Dim x As Variant
Dim Centr As Variant
Dim db As Database: Set db = CurrentDb
str = " FROM " & TableName
If vbNullString = Condition Then
Else
str = str & " WHERE " & Condition
End If
'*** the following line of code is where the error keeps comming up. ***
Set rst = db.OpenRecordset("SELECT " & FieldName & str & " ORDER BY " & FieldName, dbOpenForwardOnly, dbReadOnly)
'calculate the number of records in the dataset
n = CurrentDb.OpenRecordset("SELECT COUNT(*)" & str).Fields(0).Value
***** the next line is the call statement in the report
=Median("qWEDnetEcoData","[Lead-timeVariance]")
I get the following error message.
Run time error "3061" Too few parameters. Expected 3.