如何使用参数表单选择是否需要空值?

问题描述 投票:1回答:1

我正在研究我学校用于招生的数据库。我想在参数表单中包含一个选项,用于生成学生联系信息,允许用户选择是否在该联系人列表中包含“已应用”学生。我目前正在尝试通过使用选择查询来执行此操作,该查询根据“IdNumber”字段是否为空来提取数据。当我运行附加的SQL时,它根本不会提取任何数据。任何帮助,将不胜感激!

SELECT InterestCards.NotStudentID, InterestCards.Email, InterestCards.YearOfGraduation, 
InterestCards.SourceTwoLocation, InterestCards.FirstName, InterestCards.LastName, 
InterestCards.Program, InterestCards.Inactive, InterestCards.IDNumber 
FROM InterestCards 
WHERE (((InterestCards.Email)<>"no email") 
AND ((InterestCards.YearOfGraduation) Like [Forms]![MassCommunicationTool]![GradYear] & "*") 
AND ((InterestCards.SourceTwoLocation) Like [Forms]![MassCommunicationTool]![FairName] & "*") 
AND ((InterestCards.Inactive)=No) 
AND ((InterestCards.IDNumber)=Switch([Forms]![MassCommunicationTool]![IncludeApplied]=0,Null,[forms]![MassCommunicationTool]![IncludeApplied]=(-1),([InterestCards].[IDNumber]) Is Not Null Or ([InterestCards].[IDNumber]) Is Null)) 
AND ((InterestCards.HighSchool) Like [Forms]![MassCommunicationTool]![HighSchool] & "*") 
AND ((InterestCards.SourceThreeType) Like [Forms]![MassCommunicationTool]![SelectTerm] & "*") 
AND ((InterestCards.DateEntered) Between Nz([Forms]![MassCommunicationTool]![StartDate],#1/1/1900#) And Nz([Forms]![MassCommunicationTool]![EndDate],#1/1/2199#)));
sql ms-access
1个回答
0
投票

运算符在查询对象中不能是动态的。无法通过条件表达式选择。但是,参数可以是动态的。建议你构造一个带有表达式的字段,该表达式处理空值以返回2个值中的任何一个:

IIf([IDNumber] Is Null, "XXXX", "AAAA") AS Grp

然后要选择Null或Null记录,请将条件参数应用于该字段:

Grp = IIf([Forms]![MassCommunicationTool]![IncludeApplied]=0, "XXXX", "AAAA")

我从未使用过动态参数化查询。我更喜欢VBA构建过滤条件并应用于表单或报告。

© www.soinside.com 2019 - 2024. All rights reserved.