MS Access: Ignoring query criteria if blank

后端 未结 1 1680
既然无缘
既然无缘 2020-12-12 04:05

I have a form in Access where I run a query based on several text boxes. I apply criteria on several of the query fields that is pulled from the text boxes but would like th

相关标签:
1条回答
  • 2020-12-12 04:27

    You can try the technique described here.

    For each search box, use boolean logic to either filter for its value, or ignore this AND clause if it's empty, by making the AND clause TRUE.

    I'll just use two search boxes as example:

    SELECT stuff
    FROM Events
    
    WHERE ((Events.Machine = [Forms]![SearchEvent]![Machine_TextBox]) 
                OR ([Forms]![SearchEvent]![Machine_TextBox] Is Null))
      AND ((Events.[Event Description] Like "*" & [Forms]![SearchEvent]![EventDetails_TextBox] & "*") 
                OR ([Forms]![SearchEvent]![EventDetails_TextBox] Is Null))
      AND ...
    
    0 讨论(0)
提交回复
热议问题