Query for Reports- Sort by condition, leave blank to include all

J

Jodstar

I am making reports where I would like to use queries to include only those
with specific conditions (in the criteria box) as chosen by the user in the
ChooseReport form.

What I would like to do is have the query include all records when the
condition is left blank.

For example, on a sort by status the user could input "open" or "closed" or
all by leaving it blank (or by choosing an option if that is what I need to
do). But the principle point is that they could have those three options by
using the same button.

Thank you
 
W

Wayne-I-M

Hi

Quick answer (there are many)

Private Sub ButtonName_Click()
If IsNull(ComboOnForm) Then
DoCmd.OpenReport "ReportName", acViewPreview, "", "", acNormal
Else
DoCmd.OpenReport "ReportName", acViewPreview, "",
"[FieldInReport]=[Forms]![FormName]![ComboOnForm]", acNormal
End If
End Sub


Create a combo and use this to give the values. If not vaule is selected
you will get an unfiltered report.

Hope this helps
 
J

Jodstar

Thank you Wayne for your post...

I was hoping I might apply your advice to another problem I am having.

I have fields which are checked off in the forms where users enter
information.
I would like the user to be able to sort reports by one or more of these
criteria: for example:

The form has checkboxes for Problem1 Problem2 Problem3

I would like the user to later be able to search for records that have
Problem1 and Problem 3 in them, should they want to do taht combination.

My solution attempt has been to use a combo box with those values to select
those whose values are -1 but I receive an error "type mismatch".

Ideas?

Thanks.

Wayne-I-M said:
Hi

Quick answer (there are many)

Private Sub ButtonName_Click()
If IsNull(ComboOnForm) Then
DoCmd.OpenReport "ReportName", acViewPreview, "", "", acNormal
Else
DoCmd.OpenReport "ReportName", acViewPreview, "",
"[FieldInReport]=[Forms]![FormName]![ComboOnForm]", acNormal
End If
End Sub


Create a combo and use this to give the values. If not vaule is selected
you will get an unfiltered report.

Hope this helps

--
Wayne
Manchester, England.



Jodstar said:
I am making reports where I would like to use queries to include only those
with specific conditions (in the criteria box) as chosen by the user in the
ChooseReport form.

What I would like to do is have the query include all records when the
condition is left blank.

For example, on a sort by status the user could input "open" or "closed" or
all by leaving it blank (or by choosing an option if that is what I need to
do). But the principle point is that they could have those three options by
using the same button.

Thank you
 
Top