0

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] & "*"))
Andre
  • 26,751
  • 7
  • 36
  • 80
TheSevinator
  • 27
  • 1
  • 5

2 Answers2

0

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)
Andre
  • 26,751
  • 7
  • 36
  • 80
-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
Krish
  • 5,917
  • 2
  • 14
  • 35
  • I wasn't aware pseudocode qualified as an answer when the OP is asking about a specific language. – underscore_d Aug 09 '16 at 13:44
  • You are not aware of few things. Especially, this site serves everyone and some might be interested in different approaches. besides, i'd prefer showing them how to do than do their homework! @underscore_d – Krish Aug 09 '16 at 14:02