Report show query criteria

G

Guest

I have a report based on a query. The query has criteria that gets its
values from unbound combo boxes on a form (For example: Like
[Forms]![frmStartup].[cboStatus].[Value]). The form has many unbound combo
boxes for the user to pick and choose filtering criteria for the
corresponding fields in the query. Then there is a button on the form that
previews a report with the Report's Record Source being the query.

I want to show in the Report Header the filtering criteria choosen by the
user on the form and used by the underlying query. How can you do this?
Thanks.
 
A

Allen Browne

Provided the form remains open, you can add a text box to your report, and
set its Control Source to this:
[Forms]![frmStartup].[cboStatus]
 
G

Guest

Thanks Allen, thats a good start, but I need to go a step further. I will
need to set the Control Source from VBA. Can that be done? How? The reason
for this is because my form has many combo boxes to set criteria of the
underlying query. A user may only choose a few of the combo boxes for
filtering. I will then only want to show on the report the values the user
chose to specify from the combo boxes, ie the user changed from "all" to
something specific...Thanks in advance.

Allen Browne said:
Provided the form remains open, you can add a text box to your report, and
set its Control Source to this:
[Forms]![frmStartup].[cboStatus]

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

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

alanwf said:
I have a report based on a query. The query has criteria that gets its
values from unbound combo boxes on a form (For example: Like
[Forms]![frmStartup].[cboStatus].[Value]). The form has many unbound
combo
boxes for the user to pick and choose filtering criteria for the
corresponding fields in the query. Then there is a button on the form
that
previews a report with the Report's Record Source being the query.

I want to show in the Report Header the filtering criteria choosen by the
user on the form and used by the underlying query. How can you do this?
Thanks.
 
A

Allen Browne

Okay, what I personally do is to omit the criteria from the query.
Instead, add a command button to the form to open the report.

In the Click event of the button, build up the string to use as the
WhereCondition for OpenReport. At the same time, build another string that
will be the description of the filter in plain English. Pass the description
to the report via the OpenArgs (Access 2002 and later) or a public variable
(earlier versions.) In the Format event of the Report Header section, assign
the string to a text box that shows the description.

There's an example of building up such as filter string here:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
Although that article applies the filter to a search form, the "Extending "
section explains you can do it for a report.

Then to open the report, I use a custom function OpenTheReport() like this:
http://allenbrowne.com/AppPrintMgtCode.html#OpenTheReport
Ignore the SetupPrinter4Report() line in that code, as it is not relevant to
passing the description string.

Post back if that's not clear.

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

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

alanwf said:
Thanks Allen, thats a good start, but I need to go a step further. I will
need to set the Control Source from VBA. Can that be done? How? The
reason
for this is because my form has many combo boxes to set criteria of the
underlying query. A user may only choose a few of the combo boxes for
filtering. I will then only want to show on the report the values the
user
chose to specify from the combo boxes, ie the user changed from "all" to
something specific...Thanks in advance.

Allen Browne said:
Provided the form remains open, you can add a text box to your report,
and
set its Control Source to this:
[Forms]![frmStartup].[cboStatus]

alanwf said:
I have a report based on a query. The query has criteria that gets its
values from unbound combo boxes on a form (For example: Like
[Forms]![frmStartup].[cboStatus].[Value]). The form has many unbound
combo
boxes for the user to pick and choose filtering criteria for the
corresponding fields in the query. Then there is a button on the form
that
previews a report with the Report's Record Source being the query.

I want to show in the Report Header the filtering criteria choosen by
the
user on the form and used by the underlying query. How can you do
this?
 

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