Results 1 to 2 of 2
  1. #1
    Menelaus is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    1

    Query is excluding records with blank fields

    NOTE: This is my first attempt at building a Database in Access



    I am trying to build a query to look through a single table and show results based on input from a form (text and combo boxes). When I set the criteria to link it to the search form field, if the value in the table being queried is empty, it will omit that record. I.E. fields being searched are Date, Location, Item, and Owner. If the "Date" field is empty on the table being queried, as soon as I add the Like "*" & [Forms]![LostandFound]![Search]![LSearchDate] criteria, any records that do not have a date specified are removed from the list of results.

    Here is the SQL for the Query I set up:

    SELECT [Lost Items].LostID, [Lost Items].[Date Lost], [Lost Items].[Location Lost], [Lost Items].[Item Lost], [Lost Items].[Owner Name]
    FROM [Lost Items]
    WHERE ((([Lost Items].[Date Lost]) Like "*" & [Forms]![LostandFound]![Search]![LSearchDate] & "*") AND (([Lost Items].[Location Lost]) Like "*" & [Forms]![LostandFound]![Search]![LSearchLoc] & "*") AND (([Lost Items].[Item Lost]) Like "*" & [Forms]![LostandFound]![Search]![LSearchItem] & "*") AND (([Lost Items].[Owner Name]) Like "*" & [Forms]![LostandFound]![Search]![LSearchOwner] & "*"))
    ORDER BY [Lost Items].LostID;


    What would I need to change/add in order for it to include records with one of the fields being searched being blank and the field on the search form is blank as well? As I am new to Access, explainations of why (in laymans terms) would be greatly appreciated

    Thanks for your help.


    P.S. I appologize if this question was answered in another post. All the posts I looked at didn't seem to quite answer this question for me.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    If you want the records with null, need to handle the null. Create expression in query that converts the null to something else then apply search criteria to that field. Try:

    DateLost: Nz([Date Lost],0)


    Advise not to use spaces in names.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Query for excluding TOP N records
    By dolovenature in forum Queries
    Replies: 1
    Last Post: 09-14-2012, 03:49 PM
  2. Replies: 8
    Last Post: 08-13-2012, 04:30 AM
  3. Replies: 2
    Last Post: 05-21-2012, 02:06 PM
  4. Excluding records that contain wildcards
    By AccessUser123 in forum Programming
    Replies: 3
    Last Post: 06-09-2011, 08:17 AM
  5. searching for blank fields with a query
    By ironman in forum Queries
    Replies: 0
    Last Post: 03-04-2011, 03:48 PM

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