In access I have been trying to set up user filters on what is displayed in a subform which is a list of inspection. Other methods Ive tried looking into have not been working but I have success with the below code, It will filter if a user fills any other the filter options. What I can figure out is how to have it accept multiple filters unless I spelt out every possible combination of boxes
So is there anyway this is actually possible or do I need to look at other options?
WHERE [STATUS] = "OPEN"
AND
(ANY FORM FILTERS is not Null [Filter by all those that are not null to its matching column])
effectively is there any easy way to include a condition if a form filter is not null
SELECT Inspections.INS_ID
,Inspections.Category
,Inspections.Assigned_Officer
,Inspections.Raised_For
,Inspections.Account
,Inspections.Number
,Inspections.Street
,Inspections.Area
,Inspections.Postcode
,Inspections.Date_Raised
,Inspections.Reason
,Inspections.INS_Comments
FROM Inspections
WHERE (
((Inspections.STATUS) = "Open")
AND (([Forms]![Manage_Open]![Filter_ID]) IS NULL)
AND (([Forms]![Manage_Open]![Filter_account]) IS NULL)
AND (([Forms]![Manage_Open]![Filter_officer]) IS NULL)
AND (([Forms]![Manage_Open]![Filter_Number]) IS NULL)
AND (([Forms]![Manage_Open]![Filter_Postcode]) IS NULL)
AND (([Forms]![Manage_Open]![Filter_Category]) IS NULL)
AND (
(([Forms]![Manage_Open]![Filter_From]) IS NULL)
AND (([Forms]![Manage_Open]![Filter_To]) IS NULL)
)
)
OR (
([Forms]![Manage_Open]![Filter_ID]) IS NOT NULL
AND ([Forms]![Manage_Open]![Filter_ID]) = [Inspections].[INS_ID]
)
OR (
([Forms]![Manage_Open]![Filter_account]) IS NOT NULL
AND ([Forms]![Manage_Open]![Filter_account]) = [Inspections].[Account]
)
OR (
([Forms]![Manage_Open]![Filter_officer]) IS NOT NULL
AND ([Forms]![Manage_Open]![Filter_officer]) = [Inspections].[Assigned_Officer]
)
OR (
([Forms]![Manage_Open]![Filter_Number]) IS NOT NULL
AND ([Forms]![Manage_Open]![Filter_Number]) = [Inspections].[Number]
)
OR (
([Forms]![Manage_Open]![Filter_Postcode]) IS NOT NULL
AND ([Forms]![Manage_Open]![Filter_Postcode]) = [Inspections].[Postcode]
)
OR (
([Forms]![Manage_Open]![Filter_Category]) IS NOT NULL
AND ([Forms]![Manage_Open]![Filter_Category]) = [Inspections].[Category]
)
OR (
(
(([Forms]![Manage_Open]![Filter_From]) IS NOT NULL)
AND (([Forms]![Manage_Open]![Filter_To]) IS NOT NULL)
)
AND ([Inspections].[Raised_For]) BETWEEN (
([Forms]![Manage_Open]![Filter_From])
AND ([Forms]![Manage_Open]![Filter_to])
) )
);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…