View Single Post
  #4  
Old March 6th, 2005, 08:27 PM
Duane Hookom
external usenet poster
 
Posts: n/a
Default

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
--
Duane Hookom
MS Access MVP


"Ken Snell [MVP]" wrote in message
...
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


--

Ken Snell
MS ACCESS MVP

"Martin Watts" wrote in message
...
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