Getting a report to ignore parameters

M

Martin Watts

I have a database holding details of students and training courses. One of
the reports produces stats for selected years and selected category of
courses, the year and category being set as parameters in the underlying
query. The parameters are selected by the user from a combo box on a form.
What I would like to do is give the user the option of selecting 'All
Categories' in the combo box and the report therefore, effectively ignore
this parameter, i.e. produce a report for a selected year but showing stats
for all categories of course. How would I do it?

TIA

Martin Watts
 
K

Ken Snell [MVP]

Assuming that your query has a parameter similar to this:

Forms!FormName!ComboBoxName


Just replace it with this (assuming that the combo box is blank when you
want all records):

Forms!FormName!ComboBoxName Or Forms!FormName!ComboBoxName Is Null
 
M

Martin Watts

Excellent. Thanks for that Ken, works like a dream.

Martin Watts

in message
 
D

Duane Hookom

The method that I prefer is to not set the criteria in the query. Write code
that builds a Where clause to use in the DoCmd.OpenReport method:

Dim strWhere as String
strWhere = "1 = 1 "
If Not IsNull(Me.cboCategories) Then
'assuming the field is a text field
strWhere = strWhere & " AND [CategoryField] = """ & me.cboCategories
& """"
'if categoryField is numeric then uncomment the next line
'strWhere = strWhere & " AND [CategoryField] = " & me.cboCategories
End If
DoCmd.OpenReport "rptYourReport", acPreview, , strWhere
 
Top