Limit the number of records by altering the Record Source of the report. I'm guessing your report is based on a query or an SQL statement so it would read:
Code:
SELECT [COLOR=Red]TOP 20[/COLOR] ... etc
where TOP 20 will return a total of 20 records and nothing more. You can alter the number as you see fit.
Hi, I can't limit the number of records that come from the query because there are calculations on the report based on the whole of the query. i.e. count of records based on certain criteria. I had assumed - perhaps wrongly - there may be some code that will prevent other pages from displaying
Sorry if I didn't explain clearly, but, as stated in my previous reply, there are calculations on the report based on the details in the query. So if I limit the query to the top 10 records it will only use those for the calculations on the report e.g. I have a field on a report that counts the number of records that have a certain status, the result of the count is 4677, however, if I limit it to the top 10 results it will only count a maximum of 10 records. I hope this clarifies what I meant.
So you can put a subreport in the footer to perform and display the calculations and limit the records of the main report.
Or
Drop a textbox in the Detail section and get it to perform a Running Sum Over All > write code in the Format event of the Detail section to hide the section if the value in the textbox is greater than 20, else make the section visible.
Or
Limit the records in the report and use DCount and/or DSum to perform the calculations.
Well, putting a subreport and not allowing it to grow almost works, the only problem is I use SQL to open the report based on selections on my reporting form. I use:
DoCmd.OpenReport strReport, acViewPreview, , strSQL
How can I get it to apply the SQL to the subreport? If I can get it to use the SQL for the sub report, that will be a brilliant solution. Thanks.
Sorry if I sound really stupid, but, I am very new to all this and really appreciate your help. I don't know how to set the filter on the sub report to the SQL from my button click code. Basically the button just sets the SQL string, and then displays the report, but, I don't know how to get the code to also set the Filter of the subform to the SQL?
So on my form where I click to open the report - all the form does is allow me to select which report I want to open and select criteria - I add the following in the preview button routine:
That is a typo I made as I typed on here, in the code it was correct lol I am learning to type so try to type as much as possible instead of copy/pasting
But, this can contain loads of different things, as the criteria builder is used for lots of different reports. I am trying to get this to run with the simplest criteria first.