如何将表单中的数据导入我的查询?

时间:2016-06-29 15:35:29

标签: sql ms-access access

如果

,我想运行查询

表格!txtLanguageInd ="西班牙语"

并运行另一个查询,如果它不是

这是我的SQL查询

IIf(Forms!HiddenUserCheck!txtLanguageInd = "Spanish", 
(SELECT UserList.Clerkid, IIf([LastName]=" Smith",[LastName] & [FirstName],[FirstName] & " " & [LastName]) AS FullName, UserList.Status, UserList.ActiveToday
FROM UserList
WHERE (((UserList.Status)="Clerk") AND ((UserList.ActiveToday)=True)) OR (((UserList.Status)="Drug Court") AND ((UserList.ActiveToday)=True)) AND SpanishPrompt=True
ORDER BY IIf([LastName]=" Smith",[LastName] & [FirstName],[LastName] & ", " & [FirstName]);),
(SELECT UserList.Clerkid, IIf([LastName]=" Smith",[LastName] & [FirstName],[FirstName] & " " & [LastName]) AS FullName, UserList.Status, UserList.ActiveToday
FROM UserList
WHERE (((UserList.Status)="Clerk") AND ((UserList.ActiveToday)=True)) OR (((UserList.Status)="Drug Court") AND ((UserList.ActiveToday)=True)) AND SpanishPrompt=False
ORDER BY IIf([LastName]=" Smith",[LastName] & [FirstName],[LastName] & ", " & [FirstName]);))

2 个答案:

答案 0 :(得分:2)

我认为你的问题很重要......

SELECT IIF(SomeVariable=1,"TrueValue","FalseValue")

不能用作

IIF(SomeVariable=1,(Execute one statement),(Execute another statment))

您正在混合条件表达式和条件处理的概念......您在两个陈述结尾处放置的分号表明这一点......

错误返回多个字段指向同一个字段。如果你的两个语句只返回一个标量值,这可能会有效,但是 - 当然!没有一个完整的声明返回许多字段......

答案 1 :(得分:1)

根本不需要这个外部IIf,只需将条件放入WHERE子句中。

这应该做你想要的,但你应该检查WHERE子句中OR和AND的优先顺序,你可能想要围绕两个OR条件的另一组括号。

SELECT UserList.Clerkid, IIf([LastName]=" Smith",[LastName] & [FirstName],[FirstName] & " " & [LastName]) AS FullName, 
       UserList.Status, UserList.ActiveToday
FROM UserList

WHERE ((UserList.Status="Clerk") AND (UserList.ActiveToday=True)) 
   OR ((UserList.Status="Drug Court") AND (UserList.ActiveToday=True))
   AND SpanishPrompt=(Forms!HiddenUserCheck!txtLanguageInd = "Spanish")

ORDER BY IIf([LastName]=" Smith",[LastName] & [FirstName],[LastName] & ", " & [FirstName]);