If NotNull then...

I have simple search for where the user checks a check box next to the criteria that they would like to filter by.  But I was wonder if there was a way to remove the check box.  I have tried If Not IsNull but it does not work.  Here is the code that I use.

    If chkLegal = True Then
    If Nz(Forms![frm_Customer_Search]!txtLegalName, "") <> "" Then
        strWhere = "(Legal_Name LIKE '*" & Replace(Forms![frm_Customer_Search]!
        txtLegalName, "'", "''")  & "*') AND "
    End If
    End If
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Hi garland29,

  Not quite sure what your asking here.  Are you saying you'd like to remove the check box (chkLegal) and just use the txtLegalName control?  

And the where clause seems to be incomplete.

You get something like this:

strWhere = "(Legal_name Like '*yourvalue*') AND"
garland29Author Commented:
Yes I would like to remove the check box.  But there are about 8 text boxes with different criteria. I would like it to check if there is anything in the text box if not then move on.

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Arno KosterCommented:
so you'd want to filter on a criteria if and only if the criteria is not empty ?


    returns the length of the txtLegalName field.

if len(txtLegalName) > 0 then
end if

or you could use IsEmpty( ), IsNull( ), IsNumeric( ) etc
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:

    This is the way I usually build my WHERE clauses

    Dim strCriteria

    strWhere = ""

    If Nz(Forms![frm_Customer_Search]!txtLegalName, "") <> "" Then
        strWhere  = strWhere & "Legal_Name LIKE '*' " &  Forms![frm_Customer_Search]![txtLegalName] & " AND"
   End If

   ' Next check

   ' Strip off last AND
  If Len(strWhere)>0 then strWhere =Left$(strWhere,Len(strWhere)-4))


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
garland29Author Commented:
I love the ones that are staring right back at me;-)  Thanks!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.