filter query result based on combobox (1 Viewer)

foxtet

Registered User.
Local time
Today, 11:29
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

  • Database1.accdb
    476 KB · Views: 170

Ranman256

Well-known member
Local time
Today, 03:29
Joined
Apr 9, 2015
Messages
4,337
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.
 

sneuberg

AWF VIP
Local time
Today, 00:29
Joined
Oct 17, 2014
Messages
3,506
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

  • ComboBoxWIthAll.accdb
    396 KB · Views: 222

Users who are viewing this thread

Top Bottom