Results 1 to 8 of 8
  1. #1
    kevins is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    26

    Search Query - Retrieving records with null fields

    I have a search form that works great, but only if every field is populated. Basically, I can search for one or all of the parameters and it will retrieve records that meet those parameters. It will not, however retrieve a record if any of those fields are null. Is there a fix so that it will include records with null fields? Below is my code:

    SELECT [Candidates Extended].[Contact Name], [Candidates Extended].Company, [Candidates Extended].[Job Title], [Candidates Extended].City, [Candidates Extended].State, [Candidates Extended].Status, [Candidates Extended].[Specialty 1], [Candidates Extended].[Specialty 2], [Candidates Extended].[Specialty 3], [Candidates Extended].[Specialty 4], [Candidates Extended].Category
    FROM [Candidates Extended]


    WHERE ((([Candidates Extended].[Contact Name]) Like "*" & [Forms]![Search Form]![Name] & "*") AND (([Candidates Extended].Company) Like "*" & [Forms]![Search Form]![Company] & "*") AND (([Candidates Extended].[Job Title]) Like "*" & [Forms]![Search Form]![Job Title] & "*") AND (([Candidates Extended].City) Like "*" & [Forms]![Search Form]![City] & "*") AND (([Candidates Extended].State) Like "*" & [Forms]![Search Form]![State] & "*") AND (([Candidates Extended].Status) Like "*" & [Forms]![Search Form]![Status] & "*") AND (([Candidates Extended].[Specialty 1]) Like "*" & [Forms]![Search Form]![Specialty] & "*") AND (([Candidates Extended].[Specialty 2]) Like "*" & [Forms]![Search Form]![Specialty] & "*") AND (([Candidates Extended].[Specialty 3]) Like "*" & [Forms]![Search Form]![Specialty] & "*") AND (([Candidates Extended].[Specialty 4]) Like "*" & [Forms]![Search Form]![Specialty] & "*") AND (([Candidates Extended].Category) Like "*" & [Forms]![Search Form]![Category] & "*"));

    Thanks!

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    (([Candidates Extended].[Contact Name]) Like "*" & [Forms]![Search Form]![Name] & "*") Or IsNull([Forms]![Search Form]![Name])) And ...

    I don't know if this would work or not. I was hoping someone else would answer!

    Make a copy of this query - remove all the criteria - do the above, see if it works.
    If it works, add the next field, check your results. Etc
    It is hard to troubleshoot complex queries/issues.

    Otherwise, do you know VBA? You can make a string.

  3. #3
    kevins is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    26
    No dice...I'm an intermediate Access user at best, so I'm not familiar with VBA. I'm thinking of getting a book and trying to teach myself some tricks for Access and VBA. Any recommendations?

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Try changing your ANDs to ORs and see what you get.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Try changing your ANDs to ORs and see if that works.

    see post #12 here for similar situation
    https://www.accessforums.net/queries...ues-20931.html

  6. #6
    kevins is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    26
    The AND operator isn't what is causing the problem. The problem is that the query is only returning the records that have entries fully completed, but not those that have null entries. For example, I can type in "Dave" and the query will return only those records with the first name Dave, but only if the city, state, category fields, etc. are populated. If I don't have a category for one of the Daves, it won't retrieve that record.

  7. #7
    tommy93 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2011
    Posts
    36
    Im having the exact same issue with my query. I have a thread going about that aswell...

    I have tried both adding the wildcard &"*" and "Or IsNull" to the criteria but still no luck. Im still trying to work around it though

  8. #8
    Kenny is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    2
    Hi, I have a question I think very similar to this. I have a query that I use with an "Unbound Form". There is approximately 10 fields on this form. I want user to have the ability to search using this unbound form. Some of the field’s don’t need to be searched all the time. How can I write the query so that when a user searches some of the fields and leaves some blank it, will still get the records that they need. In the query design menu I have this code in one of the fields: [forms]![frm Query transparts]![part] what if the user wants to leave this field blank when he is doing a search but he puts data in the others. I dont know VBA..Sorry.

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

Similar Threads

  1. Search to ignore null fields
    By tommy93 in forum Queries
    Replies: 10
    Last Post: 02-07-2012, 10:58 AM
  2. Query Not Returning Null Fields
    By mgmirvine in forum Queries
    Replies: 2
    Last Post: 10-28-2011, 06:15 PM
  3. Query search wont display null fields
    By Coffee in forum Queries
    Replies: 2
    Last Post: 08-08-2011, 09:00 AM
  4. make query fields not display if null data
    By rivereridanus in forum Queries
    Replies: 1
    Last Post: 07-05-2011, 08:19 AM
  5. saving records without null or empty fields
    By amber mara in forum Access
    Replies: 1
    Last Post: 05-05-2010, 02:34 PM

Tags for this Thread

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