pass dynamic filter to report

M

miss031

I have an unbound form, and I use an option group/search box to apply a
filter to its subform. Here is an example:


If Me.frame_choose_criteria = 1 Then
Me.txt_frame_choice = 1
If Not IsNull(Me.txt_search_box) Then
Forms![sale_masters].[subform_sale_masters].Form.Filter = "seller_number =
'" & Me.[txt_search_box] & "'"
Forms![sale_masters].[subform_sale_masters].Form.FilterOn = True
End If
End If


Now, after applying that filter, I would like to print a report with that
exact criteria. How do I pass a filter to a report? OpenArgs??

I think I am missing something obvious. Thanks for any help.
 
A

Allen Browne

Try a text box bound to this expression:
=IIf([Report].[FilterOn], [Report].[Filter], Null)

There are a couple of problems with that approach:
a) It's not very pretty/readable (for a human), and
b) Access does not always maintain the report's FilterOn property correctly,
so it may be an artifact, not a real filter.

A better solution is to create another string that expresses the filter in
meaningful English. Then pass it to the report in OpenArgs (if you use
Access 2002 or later), or via a public string variable.
 
M

miss031

I figured that your second solution was the way to go, but I have 6 different
choices in the option group. What I posted is an example of one of them.

I might have to use the first solution, because I need the form to determine
which filter is applied to it so that it can pass it on.

Can I do that with a static string, or will I have to use the textbox
approach?

Allen Browne said:
Try a text box bound to this expression:
=IIf([Report].[FilterOn], [Report].[Filter], Null)

There are a couple of problems with that approach:
a) It's not very pretty/readable (for a human), and
b) Access does not always maintain the report's FilterOn property correctly,
so it may be an artifact, not a real filter.

A better solution is to create another string that expresses the filter in
meaningful English. Then pass it to the report in OpenArgs (if you use
Access 2002 or later), or via a public string variable.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

miss031 said:
I have an unbound form, and I use an option group/search box to apply a
filter to its subform. Here is an example:


If Me.frame_choose_criteria = 1 Then
Me.txt_frame_choice = 1
If Not IsNull(Me.txt_search_box) Then
Forms![sale_masters].[subform_sale_masters].Form.Filter = "seller_number =
'" & Me.[txt_search_box] & "'"
Forms![sale_masters].[subform_sale_masters].Form.FilterOn = True
End If
End If


Now, after applying that filter, I would like to print a report with that
exact criteria. How do I pass a filter to a report? OpenArgs??

I think I am missing something obvious. Thanks for any help.
 
A

Allen Browne

Try them. Both should work.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

miss031 said:
I figured that your second solution was the way to go, but I have 6
different
choices in the option group. What I posted is an example of one of them.

I might have to use the first solution, because I need the form to
determine
which filter is applied to it so that it can pass it on.

Can I do that with a static string, or will I have to use the textbox
approach?

Allen Browne said:
Try a text box bound to this expression:
=IIf([Report].[FilterOn], [Report].[Filter], Null)

There are a couple of problems with that approach:
a) It's not very pretty/readable (for a human), and
b) Access does not always maintain the report's FilterOn property
correctly,
so it may be an artifact, not a real filter.

A better solution is to create another string that expresses the filter
in
meaningful English. Then pass it to the report in OpenArgs (if you use
Access 2002 or later), or via a public string variable.

miss031 said:
I have an unbound form, and I use an option group/search box to apply a
filter to its subform. Here is an example:


If Me.frame_choose_criteria = 1 Then
Me.txt_frame_choice = 1
If Not IsNull(Me.txt_search_box) Then
Forms![sale_masters].[subform_sale_masters].Form.Filter =
"seller_number = '" & Me.[txt_search_box] & "'"
Forms![sale_masters].[subform_sale_masters].Form.FilterOn = True
End If
End If


Now, after applying that filter, I would like to print a report with
that
exact criteria. How do I pass a filter to a report? OpenArgs??
 
M

miss031

Here's what I did, and it seems to work well:


For selecting the filter:

If Me.frame_choose_criteria = 1 Then
Me.txt_frame_choice = 1
If Not IsNull(Me.txt_search_box) Then
StrWhere = "seller_number = '" & Me.[txt_search_box] & "'"
Forms![sale_masters].[subform_sale_masters].Form.Filter = StrWhere
Forms![sale_masters].[subform_sale_masters].Form.FilterOn = True
Me.txt_filter = StrWhere
End If
End If


And then to print the report:

StrWhere = Me.txt_filter
stDocName = "rpt_sale_masters_filtered"

DoCmd.OpenReport stDocName, acViewNormal, , StrWhere


Thank you very much for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top