Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

sql - Microsoft Access Query Should return true or true and false, only returns true

I am making an access query . There is a field with a Yes/No box. The query criteria parameter is IIf([Type True or All]="True",-1,>-2). But even if it evaluates to false, it only returns yes, which in access is -1, not both yes and no, which in Access is -1 and 0. If I set the criteria as >-2, then it returns both Yes and No.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Operators (=, >, LIKE, etc) cannot be dynamic. The operator must be static, then IIf() returns parameter.

Could do something like:

WHERE fieldname LIKE IIf([Type True or All] = "True", -1, "*")

Or for less typing by user:

WHERE fieldname LIKE IIf([Type "T" for True or "A" for All] = "T", -1, "*").

Or this:

WHERE fieldname LIKE Choose([Type 1 for True, 2 for False, 3 for All], -1, 0, "*")

Or for text field:
WHERE fieldname LIKE IIf([enter value or ALL]="ALL", "*", [enter value or ALL])

I don't use dynamic parameterized queries - I prefer VBA to build criteria and apply to form or report. Especially advise not to use popup inputs because they cannot be validated, inputs on form can.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...