我在MS Access中创建了一个查询,该查询引用了表单中的文本,以创建表达式的条件来按道路名称或地区在表中查找记录。
其他人最终将使用该表格,因此我使用like
通配符来灵活地在表格中输入不完整的道路名称。
不幸的是,这意味着如果将道路名称文本框留为空白,则like
函数将显示数据库中的所有记录,并且不会基于第二个标准(地区名称)对其进行限制。 / p>
我应该使用其他函数还是编写更复杂的条件?
(我曾尝试删除通配符,将Or
函数放在不同行或同一行的每个字段中,并且还考虑过添加到现有宏中,以通过区名限制查询结果,如果街道名称文本框留为空白。)
我已经使用谷歌搜索了很长时间,无法解决这个问题。谢谢您的帮助!
本质上:
表单(称为MJidea
)具有两个文本输入框-
PriStReport
)District
)查询设置:
答案 0 :(得分:0)
您可以将查询的SQL where
子句更改为:
where
(
[Forms]![MJidea]![PriStReport] is not null and
[Primary Street] like "*" & [Forms]![MJidea]![PriStReport] & "*"
) or
(
[Forms]![MJidea]![PriStReport] is not null and
[Secondary Street] like "*" & [Forms]![MJidea]![PriStReport] & "*"
) or
(
[Forms]![MJidea]![District] is not null and
[Magisterial District] like "*" & [Forms]![MJidea]![PriStReport] & "*"
)
或者,合并前两个测试:
where
(
[Forms]![MJidea]![PriStReport] is not null and
(
[Primary Street] like "*" & [Forms]![MJidea]![PriStReport] & "*" or
[Secondary Street] like "*" & [Forms]![MJidea]![PriStReport] & "*"
)
)
or
(
[Forms]![MJidea]![District] is not null and
[Magisterial District] like "*" & [Forms]![MJidea]![PriStReport] & "*"
)