View Single Post
  #2  
Old April 29th, 2008, 12:00 PM posted to microsoft.public.access.forms
strive4peace
external usenet poster
 
Posts: 1,670
Default Filter a subform by a button/toggle on the main form

Hi James,

of course smile

once you build the filter for the subform, to apply it:

'~~~~~~~~~~~~~~~~
with me.subform_controlname.form
.filter = strFilter
.FilterOn = true
end with
'~~~~~~~~~~~~~~~~

WHERE
strFilter is the string variable containing the subform filter


.... I am assuming you are talking about a subFORM and not a subREPORT.
If you really meant to say subreport, then you can save the filter
before you run the report.

put this function in a general module:

'~~~~~~~~~~~~~~~~
Sub Report_SetReportFilter(pReportName as string, pFilter as string)
'PARAMETERS
' pReportName is the name of the report
' pFilter is the filter to apply

Dim rpt As Report
DoCmd.OpenReport pReportName, acViewDesign
Set rpt = Reports(pReportName)
rpt.Filter = pFilter
rpt.FilterOn = true
DoCmd.Save acReport, pReportName
DoCmd.Close acReport, pReportName
Set rpt = Nothing
End Sub
'~~~~~~~~~~~~~~~~

where
pReportName = name of report
pFilter = filter string
******************************

before you render the report, send the report name and filter string to
the SetReportFilter sub


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day
*



James Frater wrote:
Hello Gang,

I was wondering if someone would be able to help me out.

In the main form I have an option group of toggle buttons that make the case
criteria for a report, the criteria is loaded to the report through the
on_click event of a seperate button.

Would there be anyway that when I click on one of the toggle buttons in the
option group that it could also filter a subform (based on the same query as
the report) in my main form?

I've tried a few things however no luck, so if anyone has any ideas please
give me a shout.

Regards

JAMES