Firstly don't bother sorting the query unless you are also using it
elsewhere, e.g. as the RecordSource for a form; otherwise use the report's
internal sorting and grouping mechanism to sort it. Do so even if you do
sort the query. Then in the report do the following:
1. Add an unbound text box txtTotalCount to the report header section, with
a ControlSource property of =Count(*). Set its Visible property to False
(No).
2. Add an unbound text box txtCount to the detail section, with a
ControlSource property of =1. Set its RunningSum property to 'Over All' and
its Visible property to False (No).
3. In the detail section's Format event procedure put:
Dim n As Integer
n = Me.txtTotalCount
Cancel = Me.txtCount > ((n - 1) \ 5) + 1
Note that a simple query, and consequently a report using the above will
not handle ties for the final relevant place, however, as only one of the
runners with equal times will appear in the report, so if there are 8 runners
and one is the overall winner but two tie with equal second place times, one
of the latter would unjustifiably be excluded from the report. To cater for
that you'd need to use a query which ranks the places and gives equal ranks
to ties, e.g.
SELECT R1.*,
(SELECT COUNT(*)
FROM RaceResults AS R2
WHERE R2.Race = R1.Race
AND R2.Time < R1.Time)+1 AS Position
FROM RaceResults AS R1
WHERE Race = [Enter Race:];
You'd then sort the report by Position. You'd then have a text box bound to
the position column in the detail section rather than the unbound txtCount
control, and the code in the detail sections' Format event would be:
Dim n As Integer
n = Me.txtTotalCount
Cancel = Me.Position > ((n - 1) \ 5) + 1
You refer to macros, and say that you are not be familiar with entering VBA
code in the event procedures of reports or forms. This is how its done:
Select the section by clicking on its title bar in report design view and
open its properties sheet if its not already open. Then select the Format
event property in the properties sheet. Click on the 'build' button; that's
the one on the right with 3 dots. Select 'Code Builder' in the dialogue, and
click OK. The VBA window will open at the event procedure with the first and
last lines already in place. Enter the lines of code between these two
existing lines.
Ken Sheridan
Stafford, England
pauld said:
Thanks for your response,
I use a simple query sorting on finish time from lowest to highest to
determine who is first, second, third, etc. That works just fine.
What I'm trying to do is limit the number of winners I show on the report.
The number of winners is based on the number of entries. If the number of
entries is 1-5, I award a trophy to one winnner. If the number of entries is
6-10, I award 2 trophies, etc
How do I limit the number of records I show based on the count of the
entries for that race?