2017-12-15 13 views
0

저는 학교에서 학생 모집을 위해 사용하는 데이터베이스 작업을하고 있습니다. 나는 사용자가 연락처 목록에 "적용된"학생을 포함 시킬지 여부를 선택할 수있는 학생 연락처 정보를 생성하는 데 사용되는 매개 변수 양식에 옵션을 포함하고자합니다. 나는 현재 "IdNumber"필드가 null인지 여부에 따라 데이터를 가져 오는 select 쿼리를 사용하여이를 수행하려고합니다. 첨부 된 SQL을 실행할 때 데이터를 전혀 가져 오지 않습니다. 어떤 도움을 주시면 감사하겠습니다!매개 변수 폼을 사용하여 Null 값을 사용할지 여부를 선택하려면 어떻게해야합니까?

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#))); 
+0

평등 연산자를 사용하여 null을 확인할 수 없으므로 Switch 문이 효과적이지 않습니다. SQL에서는'Is Null' 연산자를 사용하거나 VBA 함수'IsNull()'을 사용할 수 있습니다. 스위치 기능을 다른 동등한 부울 표현식으로 변경해야합니다. –

+0

Switch 문의 다른 문제는 ''매개 변수가 항상 True를 반환하는 부울 값이라는 것입니다. 이 경우 IDNumber (정수 값을 가정합니다)를 부울 True 값과 비교할 수 있습니다. 전체적으로 Switch 문은 의미가 없습니다. https://support.office.com/en-us/article/Switch-Function-d750c10d-0c8e-444c-9e63-f47504f9e379를 참조하십시오. –

답변

0

연산자는 쿼리 개체에서 동적 일 수 없습니다. 조건식을 통해 선택할 수 없습니다. 그러나 매개 변수는 동적 일 수 있습니다.

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

이 중 하나 널 여부 널 레코드를 선택 해당 필드에 조건 매개 변수를 적용 :

당신이 두 값 중 하나를 반환하는 널 (null)을 처리하는 표정으로 필드를 구성 제안 Grp = IIf([Forms]![MassCommunicationTool]![IncludeApplied]=0, "XXXX", "AAAA")

나는 동적 매개 변수화 된 검색어를 사용한 적이 없습니다. 나는 필터 기준을 구성하고 폼이나 리포트에 적용하기 위해 VBA를 선호합니다.