我在MS Access中创建了一个查询,该查询引用放入表单的文本,以创建条件表达式,以便通过道路名称或区域查找表中的记录。
其他人最终会使用表格,所以我使用like
外卡,以便在表格中灵活地输入不完整的道路名称。
不幸的是,这意味着如果将道路名称文本框留空,则like
函数会显示数据库中的所有记录,并且不会根据第二个条件(区域名称)限制它们。
我应该使用不同的功能还是编写更复杂的标准?
(我尝试删除外卡,将Or
函数放在不同行或同一行的每个字段中,如果街道名称文本框保留为空白,还考虑添加到现有宏以按地区名称限制查询结果。)
我已经谷歌搜索了一段时间,无法想出这一个。感谢您的任何帮助!
基本上:表单(称为MJidea
)有两个文本输入框 -
PriStReport
)District
)查询设置:
您可以将查询的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] & "*"
)