Results 1 to 8 of 8
  1. #1
    Nick F is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    37

    Search Form throwing out rows that have a null

    I put together a search form with seven unbound text boxes.
    Event Name: [txtEventName]
    Fiscal Year: [txtFiscalYear]
    Organizer: [txtOrganizer]
    FiN Participation: [txtParticipation]
    Month: [txtMonth]
    Day: [txtDay]


    Calender Year: [txtCalenderYear]

    The underlying query has seven columns with Criteria in each.
    Event_Name Like "*" & Nz([Forms]![Search_Form]![txtEventName],"") & "*"
    Event_Month Like "*" & Nz([Forms]![Search_Form]![txtMonth],"") & "*"
    Event_Day Like "*" & Nz([Forms]![Search_Form]![txtDay],"") & "*"
    Event_Year Like "*" & Nz([Forms]![Search_Form]![txtCalenderYear],"") & "*"
    Event_Partner_Organization Like "*" & Nz([Forms]![Search_Form]![txtOrganizer],"") & "*"
    Event_Fiscal_Year Like "*" & Nz([Forms]![Search_Form]![txtFiscalYear],"") & "*"
    Event_FiN_Participation Like "*" & Nz([Forms]![Search_Form]![txtParticipation],"") & "*"

    Each field is not required so there are many rows that have at least one null. I am trying to use the NZ function to prevent access from tossing rows that have a null in them. It doesn't seem to be working. It is only returning records with all fields filled in. I have been looking for a bit and can't find where the issue. Any help would be greatly appreciated.

  2. #2
    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,848

  3. #3
    Nick F is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    37
    SQL as requested

    SELECT Event_Main.Event_Name, Event_Main.Event_Month, Event_Main.Event_Day, Event_Main.Event_Year, Event_Main.Event_Partner_Organization, Event_Main.Event_Fiscal_Year, Event_Main.Event_FiN_Participation
    FROM Event_Main
    WHERE (((Event_Main.Event_Name) Like "*" & Nz([Forms]![Search_Form]![txtEventName],"") & "*") AND ((Event_Main.Event_Month) Like "*" & Nz([Forms]![Search_Form]![txtMonth],"") & "*") AND ((Event_Main.Event_Day) Like "*" & Nz([Forms]![Search_Form]![txtDay],"") & "*") AND ((Event_Main.Event_Year) Like "*" & Nz([Forms]![Search_Form]![txtCalenderYear],"") & "*") AND ((Event_Main.Event_Partner_Organization) Like "*" & Nz([Forms]![Search_Form]![txtOrganizer],"") & "*") AND ((Event_Main.Event_Fiscal_Year) Like "*" & Nz([Forms]![Search_Form]![txtFiscalYear],"") & "*") AND ((Event_Main.Event_FiN_Participation) Like "*" & Nz([Forms]![Search_Form]![txtParticipation],"") & "*"));

  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,848
    I just reformatted the sql
    Code:
    SELECT Event_Name
    , Event_Month
    , Event_Day
    , Event_Year
    , Event_Partner_Organization
    , Event_Fiscal_Year
    , Event_FiN_Participation
    FROM Event_Main
    WHERE 
     Event_Name  Like "*" & Nz([Forms]![Search_Form]![txtEventName],"") & "*" AND 
     Event_Month Like "*" & Nz([Forms]![Search_Form]![txtMonth],"") & "*" AND
     Event_Day  Like "*" & Nz([Forms]![Search_Form]![txtDay],"") & "*"  AND 
     Event_Year Like "*" & Nz([Forms]![Search_Form]![txtCalenderYear],"") & "*" AND
     Event_Partner_Organization Like "*" & Nz([Forms]![Search_Form]![txtOrganizer],"") & "*" AND
     Event_Fiscal_Year Like "*" & Nz([Forms]![Search_Form]![txtFiscalYear],"") & "*" AND
     Event_FiN_Participation Like "*" & Nz([Forms]![Search_Form]![txtParticipation],"") & "*";
    You have AND operators, indicating every search term should be used. Have you tried replacing the ANDs with ORs to see if that's what you're looking for?
    There is a tutorial that may be helpful at http://www.datapigtechnologies.com/f...earchform.html

  5. #5
    Nick F is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    37
    I tried putting in OR but then it returns too many rows of data. I think it is then including all rows that contain a null value.

  6. #6
    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,848
    Did you look at the tutorial? Was it helpful?
    Can you post a dumbed down version of your mdb?

    (no personal/confidential info)

  7. #7
    Nick F is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    37
    I did look at the tutorial and it turned out to be what I am basing my search form on. It just doesn't detail on how to deal with null values. Access won't let me save my current database in mdb format. Here it is in accdb.
    Attached Files Attached Files

  8. #8
    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,848

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

Similar Threads

  1. Application.FollowHyperlink throwing Exception
    By Mnelson in forum Programming
    Replies: 4
    Last Post: 03-19-2015, 02:13 PM
  2. Replies: 7
    Last Post: 09-21-2012, 03:30 PM
  3. Search Date Range with Null Sources
    By MintChipMadness in forum Forms
    Replies: 8
    Last Post: 08-23-2012, 08:56 AM
  4. Null value in search
    By Opid in forum Access
    Replies: 6
    Last Post: 05-09-2012, 01:47 PM
  5. Search to ignore null fields
    By tommy93 in forum Queries
    Replies: 10
    Last Post: 02-07-2012, 10:58 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