Results 1 to 5 of 5
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Field query no nulls and only ones with match values

    I have a form being filtered by multiple IDs that match



    However sometimes the field is null

    I don't want to show fields that are not null because that gives me all fields for some reason

    I only want IDs 1,2,3 and nothing else including no null fields.

    Not sure what I have wrong.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    You have to test for null and ignore the control ....
    Test all controls for a possible filter then build the where clause.


    Code:
    if not isnull(cboState) then   sWhere = sWhere & " and [state]='" & cboState & "'"
    if not IsNull(txtName) then    sWhere = sWhere & " and [Name]='" & txtName & "'"
    if not IsNull(chkContact) then sWhere = sWhere & " and [Contact]=" & chkContact.value
    
    
        'remove 1st And
    sWhere= mid(sWhere,5)
    
    
      'just use the filter
    
    
    me.filter = sWhere
    me.filterOn = true

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by Ruegen View Post
    I have a form being filtered by multiple IDs that match

    However sometimes the field is null

    I don't want to show fields that are not null because that gives me all fields for some reason

    I only want IDs 1,2,3 and nothing else including no null fields.

    Not sure what I have wrong.
    It's not a combo box or text field - it's a listbox.

    I for loop through it building a where sting "[CALLBACKDATE]=" & strIDs

    the strIDs is made up of the IDs

    so "23 or 45 or 55"

    (the trailing or is cut off)

    But when I add the not is null to the where it pulls up all records that are not null and just the ones I want.

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Here's an example of what I have

    It's showing results that are not null as well as the ones I don't want


    Code:
    SELECT tblAreas.AreasID, tblAreas.Area, tblAreas.TourOrganiserID
    FROM tblAreas
    WHERE (((tblAreas.Area) Like "*vic*") AND ((tblAreas.TourOrganiserID)=2) AND ((tblAreas.[AreaYearID])=17 Or (tblAreas.[AreaYearID])=16)) OR (((tblAreas.[AreaYearID]) Is Not Null));

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    This part of your criteria is returning all non null AreaYearID records

    Code:
    ....OR (((tblAreas.[AreaYearID]) IS NOT NULL));

    You might try the following sql (but I'm having difficulty understanding this line)
    It's showing results that are not null as well as the ones I don't want

    Code:
    SELECT tblAreas.AreasID
        ,tblAreas.Area
        ,tblAreas.TourOrganiserID
    FROM tblAreas
    WHERE (
            ((tblAreas.Area) LIKE "*vic*")
            AND ((tblAreas.TourOrganiserID) = 2)
            AND (tblAreas.[AreaYearID]) IN (16,17)
          )
        OR ((tblAreas.[AreaYearID]) IS NULL);

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

Similar Threads

  1. Replies: 1
    Last Post: 06-12-2015, 02:21 PM
  2. Replies: 10
    Last Post: 03-05-2015, 07:33 PM
  3. Match similar values
    By enjiel in forum Queries
    Replies: 6
    Last Post: 04-09-2014, 06:44 PM
  4. Replies: 5
    Last Post: 04-23-2013, 01:42 PM
  5. Replies: 1
    Last Post: 06-20-2007, 07:26 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