Go to the menu in report design and select View/Sort&Group. Create a
row there for your percentage field. Select Descending.
You DO NOT SORT from the query when using an Access report. If you do,
expect weird results.
Hope this helps.
Mike
"Paul Mendez" <pme...@thelyndco.com> wrote in message
news:99915b66.04061...@posting.google.com...
In Access 2000 you could view the report in design view, click View, Sorting
and Grouping, then choose the field and sort order.
Or you could amend the query, choose design view and edit the Sort field.
>
> You DO NOT SORT from the query when using an Access report. If you
> do, expect weird results.
I didn't know this. Is this true for any version of Access and does it
apply to sorting all data types?
Perhaps you could use this as a template:
SELECT p.KeyPct
, (SELECT COUNT(*) FROM tblMiscPct WHERE KeyPct >= p.KeyPct) As Rank
FROM tblMiscPct as p
ORDER BY p.KeyPct DESC;
The subquery relates to the outter queries' table alias (p) counting
the number of values equal to or greater giving a ranking.
This works with numeric values not Text values - if you have to you
can use the CDbl() conversion and lose the percentage sign:
CDbl(Left("108.2%", Len("108.2%")-1))
i.e.
CDbl(Left([KeyPct], Len([KeyPct])-1))
YMMV
'--------------
'John Mishefske
'--------------
A query/table that is sorted in the rowsource is irrelevent. I don't
know about all versions but I'll assume so. I haven't read any posts
that mention one of the new features is that you don't need to sort
reports from the Sort/Group menu option.
Value(1) = 5.0
Value(2) = 6.0
Value(3) = 5.0
Value(4) = 4.0
Team(1) = "Team Alpha"
Team(2) = "Team Gamma"
Team(3) = "Team Phi"
Team(4) = "Team Rho"
MsgBox(CStr(Team(1)) & " " & Value(1) & " " & Ranking(1, Value(),
4)) should return:
Team Alpha 5.0 2nd (tie)
If the Value and Team arrays are filled in from a SQL string that
sorts descending then:
MsgBox(CStr(Team(intI)) & " " & Value(intI) & " " & Ranking(intI,
Value(), 4)) should return:
Team Gamma 6.0 1st
Team Alpha 5.0 2nd (tie)
Team Phi 5.0 2nd (tie)
Team Rho 4.0 4th
Note: The MaxIdx of 4 can be calculated in the function from the array
rather than being passed in if the arrays are ReDim'd to the correct
size before the function call. Also, the Space function can be used
to align the results.
Function Ranking (Indx As Integer, Array() As Single, MaxIdx As
Integer) As String
'Assumes highest value in Array() is 1st and Indices start at 1
Dim NumAbove As Integer
Dim NumTied As Integer
Dim Count As Integer
Dim strOut As String
NumAbove = 0
NumTied = -1 'Don't count Indx
For Count = 1 To MaxIdx
If Array(Count) = Array(Indx) Then
NumTied = NumTied + 1
ElseIf Array(Count) > Array(Indx) Then
NumAbove = NumAbove + 1
End If
Next Count
Select Case NumAbove
Case 0: strOut = "1st"
Case 1: strOut = "2nd"
Case 2: strOut = "3rd"
Case Else: strOut = CStr(NumAbove + 1) & "th"
End Select
If NumTied > 0 Then strOut = strOut & " (tie)"
Ranking = strOut
End Function
James A. Fortune