The following query will return a group of 16 rows on the basis of the
value
entered at the parameter prompt:
SELECT TOP 16 *
FROM MyTable As T1
WHERE MyID <=
(SELECT MIN(MyID)
FROM MyTable AS T2
WHERE EXISTS
(SELECT MAX(MyID)
FROM MyTable AS T3
WHERE T2.MyID >= T3.MyID
HAVING COUNT(*) MOD (16 *[Enter group number:]) = 0))
ORDER BY MyID DESC;
where MyTable is the name of a table (or query) and MyID is a column of
unique values by which you want to order each set of 16 rows returned.
If 1
is entered at the parameter prompt the first set of 16 rows in the MyID
sort
order will be returned, if 2 is entered the second set of 16 , if 3 the
third
set of 16 and so on.
So you can open the report repeatedly and answer 1, then 2 and so on
until no
more rows are returned, in which case you can use the report's NoData
event
procedure to pop up a message box and cancel the printing by setting the
return value of the event's Cancel argument to True. Or you could
automate
the printing of the successive reports with some VBA code using a loop
which
terminates on the error occurring when the OpenReport method is called
but
the opening of the report is then cancelled by the code in its NoData
event
procedure.
One thing to note is that the query returns each set in descending order.
This is necessary for the query to work, but doesn't affect the order in
which the rows can be returned in the report as you would set its sort
order
by means of its internal sorting and grouping mechanism.
I've tested the query against a table of 1000 rows, and its performance,
while not lightning fast, should be acceptable in the context of printing
reports.
Ken Sheridan
Stafford, England
Thank you for your prompt response.
Yes, I am trying to print separate reports that have 16 records each.
I'm not sure I understand.
[quoted text clipped - 29 lines]
.