MS Access:"Like "*" &_____" 标准在留空时阻止后续字段中的 criterita 工作。请指教
MS Access: "Like "*" &_____" criteria preventing criterita from a subsequent field from working, when left blank. Please advise
我在 MS Access 中创建了一个查询,该查询引用放入表单中的文本来创建一个表达式,用于根据道路名称或地区在 table 中查找记录的条件。
其他人最终会使用该表格,所以我使用了 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] & "*"
)
我在 MS Access 中创建了一个查询,该查询引用放入表单中的文本来创建一个表达式,用于根据道路名称或地区在 table 中查找记录的条件。
其他人最终会使用该表格,所以我使用了 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] & "*"
)