如何根据用户在文本框中输入的内容进行过滤,除非显示所有内容为空

时间:2016-08-09 12:09:38

标签: ms-access access-vba

我想用查询过滤表单,以便用户必须输入他想要在文本框中搜索的内容并将其过滤掉。有一些空字段,这些字段应该显示用户是否还没有搜索过任何内容,但是如果他搜索那些字段则不再显示。

使用此代码,搜索有效,但它显示空字段:

Like("*" & [Forms].[BerichtSuche].[efTitle] & "*") OR Is Null 

我尝试了这个,但之后什么都没有显示出来:

If(Len([Forms].[BerichtSuche].[efTitle].[Text])=0; 
  Like("*" & [Forms].[BerichtSuche].[efTitle] & "*") OR Is Null; 
  Like("*" & [Forms].[BerichtSuche].[efTitle] & "*"))

2 个答案:

答案 0 :(得分:0)

所以基本上,如果搜索字段为空(空),则要显示所有记录。

在这种情况下,使用布尔逻辑使标准始终为True:

(Like "*" & [Forms].[BerichtSuche].[efTitle] & "*") 
OR ([Forms].[BerichtSuche].[efTitle] Is Null)

答案 1 :(得分:-1)

if nz(textbox.value,"") <> "" then 
    do the filter
    set the filter on. 
    or generate your own sql "Select fields from table where (field like '"& textbox.value &"') -> use the sql as rowsource/recordsource
else 
   don't do or
   clear the filter 
end if