Results 1 to 4 of 4
  1. #1
    lewis1682 is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Aug 2013
    Posts
    37

    Not all results showing in query


    Okay, so I have 2 tables - Contacts, Category. In the contacts table there is lookup value to the category table. I have a query called Search_Contacts below is the SQL code:

    Code:
    SELECT Contacts.ID, Contacts.Title, Contacts.FirstName, Contacts.LastName, Contacts.JobTitle, Contacts.Company, Contacts.AddressLine1, Contacts.AddressLine2, Contacts.Town, Contacts.County, Contacts.PostalCode, Contacts.Phone, Contacts.Fax, Contacts.Email, Contacts.Website, Contacts.Category, Contacts.Include, Contacts.Notes, Contacts.Newsletter, Contacts.AGMFROM Contacts
    WHERE (((Contacts.FirstName) Like "*" & [forms]![Filter_Contacts]![s_FirstName] & "*") AND ((Contacts.LastName) Like "*" & [forms]![Filter_Contacts]![s_LastName] & "*") AND ((Contacts.Company) Like "*" & [forms]![Filter_Contacts]![s_Company] & "*") AND ((Contacts.County) Like "*" & [forms]![Filter_Contacts]![s_County] & "*") AND ((Contacts.PostalCode) Like "*" & [forms]![Filter_Contacts]![s_PostalCode] & "*") AND ((Contacts.Category) Like "*" & [forms]![Filter_Contacts]![CategoryList] & "*"));
    If not all data fields in the table is not filled in then the query doesn't return results please help

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    The wildcard method only works if every record has a string value. Need to handle nulls. Options:

    1. use Or Is Null as criteria under each field, like
    (((Contacts.FirstName) Like "*" & [forms]![Filter_Contacts]![s_FirstName] & "*" Or Is Null)

    2. calculate alias fields to handle possible null and apply criteria to the alias field, can set these fields to not display or don't pull the native fields into query
    [FirstName] & "" AS FN

    3. use VBA procedure to construct filter criteria string and pass it in the WHERE CONDITION argument of OpenForm (or OpenReport) method
    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.

  3. #3
    lewis1682 is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Aug 2013
    Posts
    37
    I believe the 3rd method would work great, but how would I get this to do it from the textboxes and one combobox? Then it needs to show the results as a forms data where the user will cycle through the results.

    Thank you for your help.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    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 results showing table relationship
    By Steven.Allman in forum Queries
    Replies: 2
    Last Post: 04-23-2012, 01:31 PM
  2. Replies: 1
    Last Post: 03-10-2012, 03:22 PM
  3. Null Value prevents showing any results
    By nick.h in forum Queries
    Replies: 10
    Last Post: 12-19-2011, 07:23 AM
  4. Replies: 1
    Last Post: 03-09-2011, 02:04 AM
  5. Query showing unexpected results
    By johnmerlino in forum Queries
    Replies: 30
    Last Post: 10-25-2010, 07:08 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