Filtering a query via selection in cbo and if no selection filter as if blank (1 Viewer)

chrisjames25

Registered User.
Local time
Today, 10:53
Joined
Dec 1, 2014
Messages
401
Hi

I have a main form which has a subform. As i choose from combo boxes in main form the subform is filtered to less inputs based on my selection.

The criteria i am using in the query design is "Like "*" & [forms]![Frm_genusAdd]![Cbo_Tier1]"

Works great most the time, however the combobox first column is an unique id. The issue is if I choose something with unique id 5 it will also keep in the filter unique id 15 also and 25,35,45 etc.

I tried removing the "like * &" at start of criteria but then I get nothing appear in the subform. I then tried adding an Or is null but again form populates no data.

My workaround is to have afterupdate event of cbo to pass string from the second column in the cbo to a txt box and also add a criteria for that too - ""Like "*" & [forms]![Frm_genusAdd]![Txt_Tier1]". This works but i'm assuming a better way to do this.

Apologies if explained really badly.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:53
Joined
Feb 19, 2002
Messages
43,196
Since the combo provides a complete ID, there is no reason to use Like.
 

chrisjames25

Registered User.
Local time
Today, 10:53
Joined
Dec 1, 2014
Messages
401
Since the combo provides a complete ID, there is no reason to use Like.
When i get rid of the like statement then nothing appears in the subform. I think it is cos the cbo is blank at that point. What i dont know how to do is do a query design to say use cbo ID number selected but if cbo is blank use no ID
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:53
Joined
Feb 19, 2002
Messages
43,196
The criteria can be:

Where (somefield = [forms]![Frm_genusAdd]![Cbo_Tier1] OR [forms]![Frm_genusAdd]![Cbo_Tier1] Is Null)

When noting is selected, you get everything. When something is selected, you get just that.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:53
Joined
Aug 30, 2003
Messages
36,131
Which is what I suggested in the first place.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:53
Joined
Feb 19, 2002
Messages
43,196
Which is what I suggested in the first place.
Perhaps, but Chris would have needed to find the right article. I scanned the titles and couldn't pick out which one to look at.
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:53
Joined
Sep 21, 2011
Messages
14,217
Was actually the very first link on that page?
 

GPGeorge

Grover Park George
Local time
Today, 02:53
Joined
Nov 25, 2004
Messages
1,813
When i get rid of the like statement then nothing appears in the subform. I think it is cos the cbo is blank at that point. What i dont know how to do is do a query design to say use cbo ID number selected but if cbo is blank use no ID
I have a demo on my website that does this. It uses the Iif() expression and Tempvars. See if it can give you a guide to implement something similar in your situation. It is based on the exact match, but could be modified to use Like.
 

Users who are viewing this thread

Top Bottom