filter query result based on combobox

foxtet

Registered User.
Local time
Tomorrow, 01:30
Joined
May 21, 2011
Messages
129
Hi every one.
In the small db attached I have query1. I want combo box selection in the form to be filtered in the query.
combo box values include.

Morning;Evening;All. When selected All query should append all results.

Fox
 

Attachments

A table will hold the values for the 3 records, but 2 fields.
Caption, qry
Morning,qaMorn
Eve, qaEve
All,qaAll.

The combo will show col 1, for the user.
But the combo value is set to col 2.
When the user picks the item, run the query.

Docmd.openQuery combo1

It will run the append query.
 
Since you have a value list in your combo you don't need to have a union query to get All into the combo box row source. You already put it in. All you need is to use the IIF function it the queries criteria like:

Code:
IIf([Forms]![frmParam]![Combo0]="All",[Shift],[Forms]![frmParam]![Combo0])

with this function if "All" is selected in the combo box then the where clause is effectively WHERE [Shift] = [Shift] which is true for any value of Shift that is not null. Otherwise the IIF causes the WHERE clause to be effectively WHERE [Shift] = [Forms]![frmParam]![Combo0] so whatever is selected in the combo box determines the result.

If [Shift] can be Null and you want to see those records too that requires addition criteria. If you need this and can't figure it out let us know.

This IIF solution is demonstrated in the attached database.
 

Attachments

Users who are viewing this thread

Back
Top Bottom