I see the opposite in searches, but I can't find this particular setup. What I've got is a form with 8 fields which I use for my criteria in my query. If someone searches for a phrase and it matches exactly I don't have a problem, and I'm able to do a keyword search as well.
The problem I'm encountering is if there is no word at all. If the user leaves a cell blank (any of them) then the default entry which the Query enters into the search is *. This results in the user getting a list of all items in the entire table, because the search finds and matches everything. What I'm trying to figure out is how do I ignore a criteria if the value is Null? Currently my Iif Statements just aren't working right. I either get everything in the table or nothing at all.
IIf(IsNull([Forms]![Search Form]![Item Name]),Null,Like "*" & [Forms]![Search Form]![Item Name] & "*")
This returns null whether or not the form has data in that text box. I've tried multiple variations and permutations on the Iif statement with different Is Null, Not Is Null, etc trying to get the correct result, but nothing so far.
Originally I was using just this:
Like "*"&[Forms]![Search Form]![Item Name]&"*"
This would work fine as long as the text box actually had a value in it. If on the other hand the box was left blank then it automatically assumes a "*" was entered and it pulls up all records because they all match the criteria, and I don't want that.
Kyle B.
[This message has been edited by KyleB (edited 04-24-2002).]
The problem I'm encountering is if there is no word at all. If the user leaves a cell blank (any of them) then the default entry which the Query enters into the search is *. This results in the user getting a list of all items in the entire table, because the search finds and matches everything. What I'm trying to figure out is how do I ignore a criteria if the value is Null? Currently my Iif Statements just aren't working right. I either get everything in the table or nothing at all.
IIf(IsNull([Forms]![Search Form]![Item Name]),Null,Like "*" & [Forms]![Search Form]![Item Name] & "*")
This returns null whether or not the form has data in that text box. I've tried multiple variations and permutations on the Iif statement with different Is Null, Not Is Null, etc trying to get the correct result, but nothing so far.
Originally I was using just this:
Like "*"&[Forms]![Search Form]![Item Name]&"*"
This would work fine as long as the text box actually had a value in it. If on the other hand the box was left blank then it automatically assumes a "*" was entered and it pulls up all records because they all match the criteria, and I don't want that.
Kyle B.
[This message has been edited by KyleB (edited 04-24-2002).]