lartigue64
Technical User
Hi,
I have a function that calculates the median of a selection of values. This function worked fine in November when i ran the report, but in December it didn't run. It seems that i suddenly have a type mismatch error in my Median function when i try to get the number of records selected. I am wondering if I could be possibly missing a object library or something like that? I am using Access 2003.
These are the references i have checked when i go to tools/references in VBA:
* Visual Basic for Applications
* Microsoft Access 11.0 Object Library
* Microsoft DAO 3.6 Object Library
* OLE Automation
This is what my code looks like:
Public Function Median(TableName As String, FieldName As String, Condition As String)
Dim MedianDB As DAO.Database
Dim ssMedian As DAO.Recordset
Dim RCount As Integer
Dim strSQL As String
Dim x As Variant
If Condition <> "" Then
strSQL = strSQL & " WHERE " & Condition
End If
Set MedianDB = CurrentDb()
Set ssMedian = MedianDB.OpenRecordset("SELECT " & FieldName & strSQL & " ORDER BY " & FieldName, _ dbOpenDynaset)
RCount% = ssMedian.RecordCount
If n > 1 Then
ssMedian.Move n \ 2 ' move at 1/2 (round down) the way
x = ssMedian.Fields(FieldName).Value
ssMedian.Move n Mod 2
Median = 0.5 * (x + ssMedian.Fields(FieldName).Value)
Else
If n = 1 Then
Median = ssMedian.Fields(FieldName).Value
Else
Median = 0
End If
End If
ssMedian.Close
End Function
I've also tried using a select count(*) statement to get the count, but that didn't seem to work either. Any ideas?
I have a function that calculates the median of a selection of values. This function worked fine in November when i ran the report, but in December it didn't run. It seems that i suddenly have a type mismatch error in my Median function when i try to get the number of records selected. I am wondering if I could be possibly missing a object library or something like that? I am using Access 2003.
These are the references i have checked when i go to tools/references in VBA:
* Visual Basic for Applications
* Microsoft Access 11.0 Object Library
* Microsoft DAO 3.6 Object Library
* OLE Automation
This is what my code looks like:
Public Function Median(TableName As String, FieldName As String, Condition As String)
Dim MedianDB As DAO.Database
Dim ssMedian As DAO.Recordset
Dim RCount As Integer
Dim strSQL As String
Dim x As Variant
If Condition <> "" Then
strSQL = strSQL & " WHERE " & Condition
End If
Set MedianDB = CurrentDb()
Set ssMedian = MedianDB.OpenRecordset("SELECT " & FieldName & strSQL & " ORDER BY " & FieldName, _ dbOpenDynaset)
RCount% = ssMedian.RecordCount
If n > 1 Then
ssMedian.Move n \ 2 ' move at 1/2 (round down) the way
x = ssMedian.Fields(FieldName).Value
ssMedian.Move n Mod 2
Median = 0.5 * (x + ssMedian.Fields(FieldName).Value)
Else
If n = 1 Then
Median = ssMedian.Fields(FieldName).Value
Else
Median = 0
End If
End If
ssMedian.Close
End Function
I've also tried using a select count(*) statement to get the count, but that didn't seem to work either. Any ideas?