Query to filter resluts based on Combo Box

jereece

Registered User.
Local time
Today, 12:31
Joined
Dec 11, 2001
Messages
300
I have a query to filter the results of my data based on a combo box located on a form. The form Combo Box is called cbo_Status. The code I have in the Criteria section of the query is
Code:
[Forms]![frm_Main]![cbo_Status] Or Like [Forms]![frm_Main]![cbo_Status] & "*"
When I run the query, with a status selected in the Combo Box the proper results are returned. However when the Combo Box is empty, only records that have data in the Status field of the data table are returned. When the Status Combo Box is empty, I want all the data to be displayed in the query results. I have used this method before but for some reason it's not working.

Any suggestions?

Thanks,
Jim
 
You might try something along these lines (substitute highlighted text with actual names):
Code:
WHERE ( [Forms]![[B][I]frm_Main[/I][/B]]![[B][I]cbo_Status[/I][/B]] Is Null ) OR
      ( [Forms]![[B][I]frm_Main[/I][/B]]![[B][I]cbo_Status[/I][/B]] Is Not Null AND
        ( [B][I]MyTable.MyField[/I][/B] = [Forms]![[B][I]frm_Main[/I][/B]]![[B][I]cbo_Status[/I][/B]] OR
          [B][I]MyTable.MyField[/I][/B] Like [Forms]![[B][I]frm_Main[/I][/B]]![[B][I]cbo_Status[/I][/B]] & '*'
        )
      )
 
Thanks. That will work.
 
Alternatively, this might work:

Like (iif(isnull([Forms]![frm_Main]![cbo_Status]), "*", [Forms]![frm_Main]![cbo_Status]))

(untested air code)
 

Users who are viewing this thread

Back
Top Bottom