简体   繁体   English

MS Access 2016 VBA 在组合查询条件中为空

[英]MS Access 2016 VBA Is Null in combined Query Criteria

Given a Query with the criteria that uses text boxes in access.给定一个查询,其条件是在访问中使用文本框。 It works fine.它工作正常。

Like IIf(IsNull([forms]![f_form]![txt_box]),"*",[forms]![f_form]![txt_box])

The above criteria works fine when a cell has a value.当单元格具有值时,上述标准工作正常。 However, a lot of cells in the table which I search in, is null.但是,我搜索的表格中的很多单元格都是空的。

My best and logic shot was:我最好的逻辑镜头是:

   Like IIf(IsNull([forms]![f_form]![txt_box]),"*",[forms]![f_form]![txt_box])
OR Like IIf(IsNull([forms]![f_form]![txt_box]),Is Null,[forms]![f_form]![txt_box])

However, this does not work.但是,这不起作用。

If i just use "Or Is Null" then it returns all records where a cell is null even when i do a specific search.如果我只使用“Or Is Null”,那么即使我进行特定搜索,它也会返回单元格为空的所有记录。

Any suggestions?有什么建议吗?

BR, Emil. BR,埃米尔。

Edit: The solution so far was to put in "-" in all null cells, but when the users leave a cell blank (Null), the record will never show up in the filter (Query).编辑:到目前为止的解决方案是在所有空单元格中放入“-”,但是当用户将单元格留空(空)时,记录将永远不会出现在过滤器(查询)中。 Hence I do not prefer this solution.因此我不喜欢这个解决方案。

What I mean is this criteria:我的意思是这个标准:

[Forms]![f_form]![txt_box] OR ([Forms]![f_form]![txt_box] Is Null)

or if you want to support wildcard searches too (after all):或者如果您也想支持通配符搜索(毕竟):

LIKE [Forms]![f_form]![txt_box] OR ([Forms]![f_form]![txt_box] Is Null)

I would suggest using NZ instead of IIF and IsNull combination,我建议使用 NZ 而不是 IIF 和 IsNull 组合,

SearchField Like Nz([forms]![f_form]![txt_box],'*') SearchField Like Nz([forms]![f_form]![txt_box],'*')

Do you think that the txt_Box can have Zero length string instead of Null or possible that either of one can be there ?你认为 txt_Box 可以有零长度字符串而不是 Null 或者可能有一个可以在那里吗? if so you can try following如果是这样,您可以尝试关注

SearchField like iif([forms]![f_form]![txt_box]='',' ',nz([forms]![f_form]![txt_box],' ') SearchField 像 iif([forms]![f_form]![txt_box]='',' ',nz([forms]![f_form]![txt_box],' ')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM