Hello,
I am trying to build a filter query with some AND and OR.
I have three text boxes and 5 check boxes. The checkboxes are linked via code to other textboxes for the purpose of the query.
The first three text boxes are:
[CompName]
[AOName]
[GroupName]
The other five text boxes are:
[WillNot]
[Contacted]
[Promised]
[Opened]
[NotContacted]
They are all on a form and the result form on which is applied the filter query is on a sub form.
I want the user to be able to filter the data with [CompName], [AOName] & [GroupName] being all linked by AND (one excludes the other).
Then, in the meantime, the user will tick some of the five check boxes, which will activate some of the text boxes (they are not visible to the user), and all this should be OR linked (we can have some data which answers two or more of these criteria).
If there are no matching records, the query will return no results (or at best have a msgbox(“No results found”)).
My query is as follows:
But it does not work the way I want: the OR criteria are recognized and work well, whereas it does not even take into account the AND criteria.
Can someone help?
Thank you very much and best regards.
G.
I am trying to build a filter query with some AND and OR.
I have three text boxes and 5 check boxes. The checkboxes are linked via code to other textboxes for the purpose of the query.
The first three text boxes are:
[CompName]
[AOName]
[GroupName]
The other five text boxes are:
[WillNot]
[Contacted]
[Promised]
[Opened]
[NotContacted]
They are all on a form and the result form on which is applied the filter query is on a sub form.
I want the user to be able to filter the data with [CompName], [AOName] & [GroupName] being all linked by AND (one excludes the other).
Then, in the meantime, the user will tick some of the five check boxes, which will activate some of the text boxes (they are not visible to the user), and all this should be OR linked (we can have some data which answers two or more of these criteria).
If there are no matching records, the query will return no results (or at best have a msgbox(“No results found”)).
My query is as follows:
Code:
SELECT tblProspects.CompName, tblProspects.Status, tblProspects.AOName, tblProspects.GroupName, tblProspects.InputDate FROM tblProspects WHERE (((tblProspects.CompName)=[Forms]![frmMgtMain]![CompName]) AND ((tblProspects.AOName)=[Forms]![frmMgtMain]![AOName]) AND ((tblProspects.GroupName)=[Forms]![frmMgtMain]![GroupName]) AND ((tblProspects.Status)=[Forms]![frmMgtMain]![WillNot] Or (tblProspects.Status)=[Forms]![frmMgtMain]![Contacted] Or (tblProspects.Status)=[Forms]![frmMgtMain]![Promised] Or (tblProspects.Status)=[Forms]![frmMgtMain]![Opened] Or (tblProspects.Status)=[Forms]![frmMgtMain]![NotContacted])) GROUP BY tblProspects.CompName, tblProspects.Status, tblProspects.AOName, tblProspects.GroupName, tblProspects.InputDate;
Can someone help?
Thank you very much and best regards.
G.
Comment