I am trying to use a combo box in a form to select the criteria for my query. It works for filtering if you do choose a value in the combo box. However, if the combo box is left blank, I want the query to show all records for that field. However, It will not show any fields that are blank. This is not a required field, so I still want all the fields to show if there is no value in the combo box. Here is my equation:
=IIf(IsNull([Forms]![Combined Board Report Form].[Combo4]),[Medium 1],[Forms]![Combined Board Report Form].[Combo4])
You are going to have to dynamically build the SQL for the query. If the field was required you could use something like:
LIKE IIF(IsNull([Forms]![Combined Board Report Form].[Combo4]),"*",IsNull([Forms]![Combined Board Report Form].[Combo4]))
Which would provide matches if the combobox is not null and select all, *, if it was null. Unfortunately, LIKE "*" will not select records wiith Null in the field.
Define your form with nothing in the Filter property. In the change event for the combo box assign the Filter property of the form:
Me.Filter = IIF(IsNull([Forms]![Combined Board Report Form].[Combo4]),NULL,[<Field Name>]=""" & [Forms]![Combined Board Report Form].[Combo4] & """")
Me.Requery