View Full Version : Filtering a Report using Combo Box help needed


Opengrave
06-28-2002, 01:04 PM
Not sure if this is possible without VBA / SQL coding but any help would be appreciated. I am working on a database that deals with people’s talents and personality types and am trying to generate a report that can be filtered by values on 5 combo boxes on a form. The report should list everyone in the table unless the report is filtered using the combo boxes. I only want to restrict the report if the combo boxes have had values selected. I can get the report to filter based on combo box values with no problem, the problem I am having is that if I leave any of the combo boxes blank I get 0 records returned. I have to fill in all 5 combo boxes and have to have a record that meets the criteria for the query to return any records.

Basically what I want to say is if [Forms]![frmPersonalityReports]![cboPersonalityType1] is populated then filter the records by the value entered in [Forms]![frmPersonalityReports]![cboPersonalityType1] else return all records.

FrmPersonalityReports has 5 combo boxes and a button:
cboPersonalityType1
cboPersonalityType2
cboTalent1
cboTalent2
cboTalent3
and a cmdPreviewReport that opens the report

The report basically has lastname, firstname, PersonalityType1, PersonalityType2, Talent1, Talent2, Talent3

Any suggestions on how to do this with just a normal query or am I going to have to write a bunch of cases in VBA?

Alexandre
06-28-2002, 03:21 PM
Something like:
strQuery = Iif(Me.[cboPersonalityType1 ] ,"[PersonalityType1] = " & Me.[cboPersonalityType1 ],"")
strQuery = strQuery & Iif(Me.[cboPersonalityType2] ," AND [PersonalityType2] = " & Me.[cboPersonalityType2],"")
strQuery = strQuery & Iif(Me.[cboTalent1] ," AND [Talent1] = " & Me.[cboTalent1],"")
strQuery = strQuery & Iif(Me.[cboTalent2] ," AND [Talent2] = " & Me.[cboTalent2],"")
strQuery = strQuery & Iif(Me.[cboTalent3] ," AND [Talent3] = " & Me.[cboTalent3],"")

Docmd.OpenReport "ReportName", ,,strQuery

You could also look the Like operator:
strQuery = "[PersonalityType1] Like '*" & Me.[cboPersonalityType1 ] & "' AND [PersonalityType2] Like '*" & Me.[cboPersonalityType2] & etc.