Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Filter fields including records with null

    I have a multi search form that filters multiple fields using unbound text boxes




    Code:
    Me.frmSchoolSearchSub1.Form.Filter = "[NewSchoolsID] Like '*" & Me.txtIDnumber & "*'" & IIf(Not IsNull(Me.cmbState), " and StateID=" & Me.cmbState, "") & " and [SchoolName] Like '*" & Me.txtSchoolS & "*'" & "and [SchoolSuburb], Like '*" & Me.txtSchoolSub & "*'" & "and [SchoolPostCode] Like '*" & Me.txtFilterSchoolPostCode & "*'" & "and isnull(Removed)" & "and [SchoolPhone] Like '*" & Me.txtPhone & "*'"
    Me.frmSchoolSearchSub1.Form.FilterOn = True
    However if one or more of those fields happen to be blank then they won't show.

    Is there a way to make a field if null still show?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Two ways to handle:

    1. Include Is Null in the criteria for each field

    "and ([SchoolPostCode] Is Null Or [SchoolPostCode] Like '*" & Me.txtFilterSchoolPostCode & "*')"

    2. Convert the null to a string with an expression in query and apply criteria to the calculated field

    "and Nz([SchoolPostCode],"") Like '*" & Me.txtFilterSchoolPostCode & "*'"
    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
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Two ways to handle:

    1. Include Is Null in the criteria for each field

    "and ([SchoolPostCode] Is Null Or [SchoolPostCode] Like '*" & Me.txtFilterSchoolPostCode & "*')"

    2. Convert the null to a string with an expression in query and apply criteria to the calculated field

    "and Nz([SchoolPostCode],"") Like '*" & Me.txtFilterSchoolPostCode & "*'"
    I don't think I can use option one because I don't want to show records just because they have a null (I want to say search a name, but if the name is missing say a post code then it won't show).

    Option gives me a 3075 error unless I use ' ' instead of "" however it is still not giving me results.

    The query record source works fine - just when filtering it doesn't.

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    As you can see in the image - there is a record with a missing name field.

    If I filter the form id 9330 (green form) I get no result.

    Click image for larger version. 

Name:	Capture.JPG 
Views:	12 
Size:	70.5 KB 
ID:	15204

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I am confused. If you want to return record even if one of the data fields has null, must handle the null value with one of the two methods.

    Also, don't include in criteria string if there is no value in the input.

    Review: http://www.allenbrowne.com/ser-62code.html
    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.

  6. #6
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    I am confused. If you want to return record even if one of the data fields has null, must handle the null value with one of the two methods.

    Also, don't include in criteria string if there is no value in the input.

    Review: http://www.allenbrowne.com/ser-62code.html
    Each textbox has an after update event

    each one filters the whole subform continuous list - depending on what is in all the text boxes

    so if there is say no text in textbox1 but text in textbox2 then it will filter the subform records to say "" in textbox1 and XYZ in textbox2 after the update

    this is so the user can say start searching by a name, then narrow the list down to say postcode later

    there is no end filter button - it searches as you tab fields or press enter on the keyboard.

    However

    If the record has no data in the field but has data in all the other searched fields it still won't show.

    I type in the ID of the school in the image above and because it is missing a school name for that ID - the record won't show once filtered.

    I tried nz([field] but I get a 3075 error

    I am not sure on the concatenation or if this can be done.

    I looked at the link - I see that it is multiple text boxes and one button that has a click event to filter the form to whatever the text boxes have, but that works differently to mine...

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Button click or AfterUpdate, code is the same, with minor adaptation. The procedure can be an unattached sub behind the form that is called by any event you want.

    Sub FilterRecords()
    ...code
    End Sub

    Sub textboxname_AfterUpdate()
    Call FilterRecords
    End Sub

    What is the exact message of the 3075 error? Show the exact code using Nz.
    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.

  8. #8
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Button click or AfterUpdate, code is the same, with minor adaptation. The procedure can be an unattached sub behind the form that is called by any event you want.

    Sub FilterRecords()
    ...code
    End Sub

    Sub textboxname_AfterUpdate()
    Call FilterRecords
    End Sub

    What is the exact message of the 3075 error? Show the exact code using Nz.
    yeah I guess I could do that (would look cleaner too)

    I have (and please note all single ' have been replaced with " to accommodate adding ' in the text boxes)

    Click image for larger version. 

Name:	Capture.JPG 
Views:	12 
Size:	25.9 KB 
ID:	15205

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Part of the issue may be the double *.

    Not including criteria if there is no value input might resolve this.

    Couldn't hurt to try.
    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.

  10. #10
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Part of the issue may be the double *.

    Not including criteria if there is no value input might resolve this.

    Couldn't hurt to try.
    um... stupid question and refresher

    how do I

    "Not including criteria if there is no value input might resolve this."?

    if isnull(me.txtbox) then etc?

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    That's right, like the Allen Browne code. Construct criteria string with conditional code.
    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.

  12. #12
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    That's right, like the Allen Browne code. Construct criteria string with conditional code.
    am using

    Code:
    Sub FilterRecords()
    
    
    Dim StrState As String
    Dim StrName As String
    Dim StrPostCode As String
    Dim StrSuburb As String
    Dim StrPhone As String
    Dim StrRemov As String
    Dim StrID As String
    
    
    Dim strConSearch As String
    
    
    StrID = "[NewSchoolsID] Like ""*" & Me.txtIDnumber & "*"""
    
    
    StrName = IIf(IsNull(Me.txtSchoolS), "", " and [SchoolName] Like ""*" & Me.txtSchoolS & "*""")
    
    
    StrState = IIf(Not IsNull(Me.cmbState), " and [StateID] =" & Me.cmbState, "")
    
    
    StrPostCode = IIf(IsNull(Me.txtFilterSchoolPostCode), "", " and [SchoolPostCode] Like ""*" & Me.txtFilterSchoolPostCode & "*""")
    
    
    StrSuburb = IIf(IsNull(Me.txtSchoolSub), "", " and [SchoolSuburb] Like ""*" & Me.txtSchoolS & "*""")
    
    
    StrPhone = IIf(IsNull(Me.txtPhone), "", " and [SchoolPhone] Like ""*" & Me.txtPhone& "*""")
    
    
    StrRemov = " and IsNull([Removed])"
    
    
    strConSearch = StrID & StrName & StrState & StrPostCode & StrSuburb & StrPhone & StrRemov
    
    
    Me.frmSchoolSearchSub1.Form.Filter = strConSearch
    Me.frmSchoolSearchSub1.Form.FilterOn = True
    
    
    End Sub
    however it is still not displaying records with empty fields...

  13. #13
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Update - it only seems to be when I search using the Me.txtIDnumber textbox...

    and only if the school is missing SchoolName

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Is IDnumber a text or number type field?
    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.

  15. #15
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    txtIDnumber is General Number.... to avoid any character other than a number...

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 01-21-2014, 11:35 AM
  2. Replies: 3
    Last Post: 05-10-2013, 10:49 PM
  3. Replies: 7
    Last Post: 05-23-2012, 02:19 PM
  4. saving records without null or empty fields
    By amber mara in forum Access
    Replies: 1
    Last Post: 05-05-2010, 02:34 PM
  5. Query including Null relationship?
    By David Criniti in forum Database Design
    Replies: 0
    Last Post: 08-14-2009, 09:10 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