The simplest way to filter a subreport is to use the Master/Child Link
Fields (properties of the subreport control.)
For example, say Form1 has a on option group named Frame1, and if option
value 2 is chosen, you want to filter the subreport to only the records
where AmountDue is zero. You put a text box on the main report, and give it
these properties:
Control Source =-1
Name txtTrue
Then put a text box in the subreport, with properties:
Control Source =IIf([Forms].[Form1].[Frame1]=2, [AmountDue]=0, -1)
Name txtFilterFlag
Now let's assume the LinkMasterFields/LinkChildFields already have the ID
field in them. You add these 2 new text box names to the properties, like
this:
Link Master Fields [ID], [txtTrue]
Link Child Fields [ID], [txtFilterFlag]
The text box on the main report is always -1, which in Access is the value
for True. If the frame on the form is set to any value other than 2,
txtFilterFlag also returns True for everything, so it's not filtered. If the
frame is value 2, then the expression will be true only in the records when
the amount due is filtered, so they are the only ones that will show up, and
so the subreport is filtered.
Another way to approach this is to set up the subreport's query to its
criteria read the frame on the control and return only true records.
Finally, if neither of those approaches work, you can programmatically
write the SQL property of the QueryDef that the subreport reads from, before
opening the report.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Reply to group, rather than allenbrowne at mvps dot org.
RSunday said:
I have a main report displaying records. I open the report from a form.
Each record has a number of "child" records. I display those in a a
subreport.
Now I want to to have a radio-button on my form to allow the user to
filter
some records.
But I have trouble applying the filter to my subreport.
Is there a way to do that?