Hello Fernando,
I was trying to understand how to use the Excel Function PercentageRank when I saw your post at
http://p2p.wrox.com/topic.asp?TOPIC_ID=41465
I am not a programmer but I need to rank some University resources with the Excel Function PercentageRank within a MS Access Database.
I tried to use your code by creating a module:
-----------------------------------------------------------
Public Function PRank(Tbl As String, Fld As String, Value As Double) As Double
Static Data() As Double
Static RecCount, FirstRunCompleted, LastRun As Integer
Dim x, y As Integer
If FirstRunCompleted = 0 Then
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open "Select " & Fld & " from " & Tbl & _
" Group by [" & Tbl & "]." & Fld & _
" Order by [" & Tbl & "]." & Fld & " DESC", _
CurrentProject.Connection, adOpenStatic
RecCount = rst.RecordCount
ReDim Data(RecCount - 1)
For x = 0 To (RecCount - 1)
Data(x) = rst(Fld)
rst.MoveNext
Next x
FirstRunCompleted = 1
rst.Close
Set rst = Nothing
End If
For x = 0 To (RecCount - 1)
If Data(x) = Value Then
y = x + 1
Exit For
End If
Next x
If x = (RecCount - 1) Then
LastRun = 1
End If
PRank = (RecCount - y) / (RecCount - 1)
If LastRun = 1 Then
ReDim Data(0)
FirstRunCompleted = 0
LastRun = 0
RecCount = 0
Exit Function
Else
Exit Function
End If
End Function
-----------------------------------------------------------
I then tried to call the module within a query with the following expression:
---------------------------------------------
Expr1: PRank([SITES],[SITES]![AlexaRank],2)
---------------------------------------------
Where [SITES] is the Table
[SITES]![AlexaRank] is the field with the values
And 2 is the Value (I guess the number of decimal places)
When I try to run the query, however I get the following error:
"Undefined Function "Prank" in expression"
The Prank module is however saved and present so I do not understand why I get this error
Should you know any other way to use the Excel Function PercentageRank, I would really appreciate.
Thank you for your help.
FF