Question : Filter Records on Form by One Comob Box or If blank, by Multiple Other Combo Box Selections

I have a number of filters setup on my form to filter through a batch of reports.

I want to allow the user to filter by multiple combo box selections. However, when they filter for the exact ReportID (using the cboFilter_ReportID combo box), I want that to override all other filters and just show the selected report.

I'm using the code below.

The important field is ReportID. In the query I'm trying to say:

IF [cboFilter_ReportID] IS NOT NULL, Then
    filter ReportID = cboFilter_ReportID
ELSE
   filter ReportID criteria by all other combo box filters
END IF

So far, the code below will allow me to filter to an exact Report when I select a report from cboFilter_ReportID.

However, when there is NO specific report selected, I want it to show all reports. Currently, it is showing NONE.

What am I missing?

(for a pic of the form setup see my previous question: http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_24416558.html)
Code Snippet:
1:
2:
3:
SELECT Reports.*
FROM FunctionalAreas INNER JOIN Reports ON FunctionalAreas.FunctionalAreaID = Reports.FunctionalAreaID
WHERE (((Reports.ReportID) Like nz([Forms]![frmReports]![cboFilter_ReportID],([Reports].[ReportID] In (SELECT DISTINCT ReportID FROM Reports WHERE ((Reports.Title like ("*" & nz([Forms]![frmReports]![txtSearch],"") &  "*")  )) ) Or ([Reports].[ReportID]) In (SELECT DISTINCT ReportID FROM Reports WHERE ((Reports.FunctionalAreaSub1 like ("*" & nz([Forms]![frmReports]![txtSearch],"") &  "*")  )) ) Or ([Reports].[ReportID]) In (SELECT DISTINCT ReportID FROM Reports WHERE ((Reports.FunctionalAreaSub2 like ("*" & nz([Forms]![frmReports]![txtSearch],"") &  "*")  )) ) Or ([Reports].[ReportID]) In (SELECT DISTINCT ReportID FROM Reports WHERE ((FunctionalAreas.Abbrev like ("*" & nz([Forms]![frmReports]![txtSearch],"") &  "*"))))))) AND ((Reports.FunctionalAreaID) Like nz([Forms]![frmReports]![cboFilter_FunctionalAreaID],"*")) AND ((Reports.FunctionalAreaSub1) Like nz([Forms]![frmReports]![cboFilter_FunctionalAreaSub1],"*")) AND ((Reports.FunctionalAreaSub2) Like nz([Forms]![frmReports]![cboFilter_FunctionalAreaSub2],"*")));
Open in New Window Select All

Answer : Filter Records on Form by One Comob Box or If blank, by Multiple Other Combo Box Selections

Okay found out what I was doing wrong. Got a bit lost in all the code. Working code is below...
1:
2:
3:
4:
SELECT Reports.*, FunctionalAreas.FunctionalArea, FunctionalAreas.Abbrev
FROM FunctionalAreas INNER JOIN Reports ON FunctionalAreas.FunctionalAreaID = Reports.FunctionalAreaID
WHERE (((Reports.FunctionalAreaSub1) Like nz([Forms]![frmReports]![cboFilter_FunctionalAreaSub1],"*")) AND ((Reports.FunctionalAreaSub2) Like nz([Forms]![frmReports]![cboFilter_FunctionalAreaSub2],"*")) AND ((Reports.ReportID) In (SELECT DISTINCT ReportID FROM Reports WHERE ((  Reports.ReportID Like nz([Forms]![frmReports]![cboFilter_ReportID_Only],"*")) )) And ((Reports.ReportID) In (SELECT DISTINCT ReportID FROM Reports WHERE ((  Reports.Title like ("*" & nz([Forms]![frmReports]![txtSearch],"") &  "*")  )) ) Or (Reports.ReportID) In (SELECT DISTINCT ReportID FROM Reports WHERE ((Reports.FunctionalAreaSub1 like ("*" & nz([Forms]![frmReports]![txtSearch],"") &  "*")  )) ) Or (Reports.ReportID) In (SELECT DISTINCT ReportID FROM Reports WHERE ((Reports.FunctionalAreaSub2 like ("*" & nz([Forms]![frmReports]![txtSearch],"") &  "*")  )) ) Or (Reports.ReportID) In (SELECT DISTINCT ReportID FROM Reports WHERE ((FunctionalAreas.Abbrev like ("*" & nz([Forms]![frmReports]![txtSearch],"") &  "*")))))) AND ((Reports.FunctionalAreaID) Like nz([Forms]![frmReports]![cboFilter_FunctionalAreaID],"*")))
ORDER BY FunctionalAreas.FunctionalArea, FunctionalAreas.Abbrev, Reports.FunctionalAreaSub1, Reports.FunctionalAreaSub2;
Open in New Window Select All
Random Solutions  
 
programming4us programming4us