在 MS Access 中查询基于表单中多个组合框的所有记录
Querying all the records based on multiple combo boxes from a form, in MS Access
请帮我解决这个问题。我有 2 个组合框(函数名称和年份)。我想根据这些组合框查询结果,如果这些框留空,则显示所有记录。我使用了以下代码,它仅适用于 1 个组合框:
=[Forms]![YourForm]![YourCombo] OR [Forms]![YourForm]![YourCombo] IS NULL
当我对第二个组合框应用相同的逻辑时,结果没有显示。以下是我使用的代码:
FROM Master_DataBase
WHERE (((Master_DataBase.Status_of_Project)="Completed"))
GROUP BY Master_DataBase.Function, Master_DataBase.Project_Name, Year([Project_Start_Date])
HAVING (((Master_DataBase.Function)=[Forms]![Navigator_Form]![FilterbyFunction])) OR ((([Forms]![Navigator_Form]![FilterbyFunction]) Is Null)) AND
(((Master_DataBase.Function)=[Forms]![Navigator_Form]![FilterbyYear])) OR ((([Forms]![Navigator_Form]![FilterbyYear]) Is Null))
ORDER BY Count(Master_DataBase.Status_of_Project) DESC;
我已附上表格组合框图片供您参考。
再附一张(设计图)供参考:
首先修复您的错误:
HAVING (((Master_DataBase.Function)=[Forms]![Navigator_Form]![FilterbyFunction])) 或 ((([Forms]![Navigator_Form]![ FilterbyFunction]) 为 Null)) AND
(((Master_DataBase.Function)=[Forms]![Navigator_Form]![FilterbyYear])) 或 ((([Forms]![Navigator_Form]![FilterbyYear]) 为 Null) )
至
HAVING (((Master_DataBase.Function)=[Forms]![Navigator_Form]![FilterbyFunction])) 或 ((([Forms]![Navigator_Form]![ FilterbyFunction]) 为 Null)) AND
(((Year(Master_DataBase.Project_Start_Date))=[Forms]![Navigator_Form]![FilterbyYear])) 或 ((([Forms]![Navigator_Form]![FilterbyYear]) 为空))
编辑:
我只想将整个表达式简化为:
HAVING Master_DataBase.Function=Nz([Forms]![Navigator_Form]![FilterbyFunction],Master_DataBase.Function)
AND Year(Master_DataBase.Project_Start_Date)=Nz([Forms]![Navigator_Form]![FilterbyYear],Year(Master_DataBase.Project_Start_Date))
请帮我解决这个问题。我有 2 个组合框(函数名称和年份)。我想根据这些组合框查询结果,如果这些框留空,则显示所有记录。我使用了以下代码,它仅适用于 1 个组合框:
=[Forms]![YourForm]![YourCombo] OR [Forms]![YourForm]![YourCombo] IS NULL
当我对第二个组合框应用相同的逻辑时,结果没有显示。以下是我使用的代码:
FROM Master_DataBase
WHERE (((Master_DataBase.Status_of_Project)="Completed"))
GROUP BY Master_DataBase.Function, Master_DataBase.Project_Name, Year([Project_Start_Date])
HAVING (((Master_DataBase.Function)=[Forms]![Navigator_Form]![FilterbyFunction])) OR ((([Forms]![Navigator_Form]![FilterbyFunction]) Is Null)) AND
(((Master_DataBase.Function)=[Forms]![Navigator_Form]![FilterbyYear])) OR ((([Forms]![Navigator_Form]![FilterbyYear]) Is Null))
ORDER BY Count(Master_DataBase.Status_of_Project) DESC;
我已附上表格组合框图片供您参考。
再附一张(设计图)供参考:
首先修复您的错误:
HAVING (((Master_DataBase.Function)=[Forms]![Navigator_Form]![FilterbyFunction])) 或 ((([Forms]![Navigator_Form]![ FilterbyFunction]) 为 Null)) AND (((Master_DataBase.Function)=[Forms]![Navigator_Form]![FilterbyYear])) 或 ((([Forms]![Navigator_Form]![FilterbyYear]) 为 Null) )
至
HAVING (((Master_DataBase.Function)=[Forms]![Navigator_Form]![FilterbyFunction])) 或 ((([Forms]![Navigator_Form]![ FilterbyFunction]) 为 Null)) AND (((Year(Master_DataBase.Project_Start_Date))=[Forms]![Navigator_Form]![FilterbyYear])) 或 ((([Forms]![Navigator_Form]![FilterbyYear]) 为空))
编辑:
我只想将整个表达式简化为:
HAVING Master_DataBase.Function=Nz([Forms]![Navigator_Form]![FilterbyFunction],Master_DataBase.Function)
AND Year(Master_DataBase.Project_Start_Date)=Nz([Forms]![Navigator_Form]![FilterbyYear],Year(Master_DataBase.Project_Start_Date))