Results 1 to 4 of 4
  1. #1
    techtony is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    18

    Search Query problem with nulls

    I have a customer table has a query that depends on a search form that asks for a phone number.




    There are four phone number fields - Home, Cell, Work and Other

    There will be at least 1 number in at least ONE of those fields.

    The problem is when you search for a customer by telephone number. I want to enter the phone number in a search field in a search form. If I enter a phone number in the search form, and one of the phone numbers are NULL, then the record is ignored and not displayed.

    Here is the query I am using:

    SELECT
    Customers.customer_id,
    Customers.first_name,
    Customers.last_name,
    Customers.company_name,
    Customers.address_1,
    Customers.city,
    Customers.zipcode,
    Customers.home_phone,
    Customers.cell_phone,
    Customers.work_phone,
    Customers.other_phone
    FROM
    Customers
    WHERE
    (((Customers.first_name) Like "*" & [Forms]![Customer Search Form]![fname])
    AND
    ((Customers.last_name) Like "*" & [Forms]![Customer Search Form]![lname] & "*")
    AND
    ((Customers.home_phone) Like "*" & [Forms]![Customer Search Form]![phone] & "*")
    AND
    ((Customers.cell_phone) Like "*" & [Forms]![Customer Search Form]![phone] & "*")
    AND
    ((Customers.work_phone) Like "*" & [Forms]![Customer Search Form]![phone] & "*")
    AND
    ((Customers.other_phone) Like "*" & [Forms]![Customer Search Form]![phone] & "*"));

    I have been reading up on Null values, but everything seems to either exclude all records that contain NULL or include all records that contain NULL. I want to simply find a match for the phone number on any of these telephone related fields.

    Any suggestions?

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Perhaps your issue is the AND operator

    Perhaps the OR operator better suits your needs.

  3. #3
    techtony is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    18
    no, not the AND vs OR - this is a null problem. Does anyone know how to handle nulls in this situation?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    One way:

    AND
    ((Customers.cell_phone) Like "*" & [Forms]![Customer Search Form]![phone] & "*" Or Is Null)
    AND

    Another is to convert the nulls to a string by expression in query and apply the filter parameter to the constructed field:

    (Nz(Customers.cell_phone,"") Like "*" & [Forms]![Customer Search Form]![phone] & "*")
    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. Nulls problem, hmm
    By redbull in forum Programming
    Replies: 6
    Last Post: 06-29-2012, 12:16 PM
  2. Count Query w/o ignoring Nulls
    By Dulanic in forum Queries
    Replies: 3
    Last Post: 03-21-2012, 11:56 AM
  3. handling nulls in mulitple parameter query
    By haggisns in forum Queries
    Replies: 5
    Last Post: 10-14-2010, 02:09 PM
  4. Replies: 2
    Last Post: 01-18-2010, 11:52 AM
  5. Replies: 1
    Last Post: 07-14-2008, 12:15 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