How to filter by what the user enters in a textbox, except show all if it's empty

那年仲夏 提交于 2019-12-29 09:51:28

问题


I want to filter a form with a query, so that the user has to input what he would like to search in a textbox and it gets filtered out. There are some empty fields, and these should show if the user has not searched for anything yet, but if he searches those should not be shown anymore.

With this code, the searching works, but it shows the empty fields:

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

I tried this, but then nothing at all is shown:

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

回答1:


So basically, if the search field is empty (Null), you want to show all records.

Use Boolean logic to make the criterion always True in this case:

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



回答2:


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


来源:https://stackoverflow.com/questions/38850333/how-to-filter-by-what-the-user-enters-in-a-textbox-except-show-all-if-its-empt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!