Results 1 to 2 of 2
  1. #1
    WesHarding is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    60

    Addition of "Like" criteria into query results in records with said criteria as null to not appear

    Hi Everyone,

    My issue is confusing enough to make a title for, let alone explain, so please be patient with me.

    I have a search form, that is comprised of a number of text boxes. Like many search forms, I want one to type in a name to recieve results from my query. I have just realized that when I add any criteria to my query to filter my records, they end up not detecting some records (they no longer appear in the query result that should show all records). Further more, these records that are not appearing are ones that don't have any information in the field that the criteria is designed to filter.

    Have any of you ever come across this before?

    I originally thought this was an AND or OR issue, but it's occuring with only one criteria!! SOS!

    SQL for query:
    SELECT
    tblWHO.FarmName,
    tblWHO.FarmCivicAddress,


    tblWHO.FarmCommunity,
    tblWHO.VERIFIED,
    tblWHO.Phone1C1,
    tblWHO.Phone2C1,
    tblWHO.Email,
    tblWHO.Website,
    tblWHO.Facebook,
    tblWHO.Notes,
    tblWHO.FarmerID,
    tblContacts.FirstName1,
    tblContacts.LastName1,
    tblWHO.Municipality_WHO
    FROM tblWHO LEFT JOIN tblContacts ON tblWHO.FarmerID = tblContacts.FarmerContactID
    WHERE (((tblWHO.FarmCommunity) Like "*" & [Forms]![MainSearchForm]![txtcommunity] & "*"));

    Wesley

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    Your query as written will:

    1. If txtcommunity is blank, return all records where FarmCommunity is not null (essentially like "*") KEEP IN MIND - this may find strings with no printable characters like line feeds
    2. if txtcommunit is NOT blank, return all records matching the typed string (like "*test*")

    if you want to show blank records when you leave txtcommunity blank you may need to do something other than test for null

    i.e.

    WHERE (((tblWHO.FarmCommunity) Like "*" & [Forms]![MainSearchForm]![txtcommunity] & "*") AND len(trim([farmcommunity])) > 0);

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 09-24-2016, 11:29 PM
  2. Replies: 2
    Last Post: 05-06-2015, 02:11 PM
  3. Simple "Or is null" Criteria question
    By floyd in forum Queries
    Replies: 2
    Last Post: 11-22-2013, 10:05 AM
  4. Replies: 4
    Last Post: 03-23-2012, 01:18 PM
  5. Passing criteria "NULL" or "IS NOT NULL" to a query
    By SgtSaunders69 in forum Forms
    Replies: 1
    Last Post: 12-24-2011, 02:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums