IIf基于用户定义参数的功能

时间:2011-04-17 13:13:06

标签: forms ms-access iif-function

我正在尝试根据输入到表单中的参数开发查询。我想确保查询仍然有效,即使用户选择不输入参数(例如开始和结束日期),或者用户只输入一半参数(例如用户只输入开始但不是结束日期或结束但不是开始日期)。这就是我想要的:

如果开始日期和结束日期为空,则返回所有日期

否则,如果开始日期为空,则返回小于或等于给定结束日期的日期

else,如果结束日期为空,则返回大于或等于给定开始日期的日期

否则,返回给定开始日期和结束日期之间的所有日期

我提出的内容似乎没有超出第一个真实陈述的评估,我不确定原因。

IIf(IsNull([forms]![Volunteer_Hours_By_Person]![Volunteer_Hours_By_Person_Start_Date]
And [forms]![Volunteer_Hours_By_Person]![Volunteer_Hours_By_Person_End_Date]),  
[Volunteer_Date],  

IIf(IsNull([forms]![Volunteer_Hours_By_Person]![Volunteer_Hours_By_Person_Start_Date]),  
<= [forms]![Volunteer_Hours_By_Person]![Volunteer_Hours_By_Person_End_Date],  

IIf(IsNull([forms]![Volunteer_Hours_By_Person]![Volunteer_Hours_By_Person_End_Date]),  
>= [forms]![Volunteer_Hours_By_Person]![Volunteer_Hours_By_Person_Start_Date],  

(Between [forms]![Volunteer_Hours_By_Person]![Volunteer_Hours_By_Person_Start_Date] 
And [forms]![Volunteer_Hours_By_Person]![Volunteer_Hours_By_Person_End_Date]))))

1 个答案:

答案 0 :(得分:0)

知道了!

WHERE (IIf(IsNull([Forms]![Volunteer_Hours_By_Person]!      [Volunteer_Hours_By_Person_Name_Selection]),(People.PID) like "*",(People.PID)=[Forms]![Volunteer_Hours_By_Person]![Volunteer_Hours_By_Person_Name_Selection]))

AND (IIf(IsNull([forms]![Volunteer_Hours_By_Person]![Volunteer_Hours_By_Person_Start_Date]) AND IsNull([forms]![Volunteer_Hours_By_Person]![Volunteer_Hours_By_Person_End_Date]),(Volunteer.Volunteer_Date) like "*",([Volunteer].[Volunteer_Date]) Between [forms]![Volunteer_Hours_By_Person]![Volunteer_Hours_By_Person_Start_Date] And [forms]![Volunteer_Hours_By_Person]![Volunteer_Hours_By_Person_End_Date]))
相关问题