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

    Basic filter question... filter with like

    Trying to filter with like



    I have

    Code:
    Me.Filter = "[Area] Like" & "*" & Me.Text36 & "*"
    Me.FilterOn = True
    however I get an error and I am not sure as to why...

  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
    Is Area a text field?

    LIKE is a text comparison operator. Need text delimiters:

    Me.Filter = "[Area] Like '*" & Me.Text36 & "*'"
    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
    Is Area a text field?

    LIKE is a text comparison operator. Need text delimiters:

    Me.Filter = "[Area] Like '*" & Me.Text36 & "*'"
    thanks - noted

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Working on it now and the filter works however

    I have two controls, one is a textbox and one is a drop down

    I want to filter correctly using either of those two or in combination

    so area is filtered by the text box and organiser is filtered by the combo box

    I tried

    Code:
    Me.Filter = "[Area] Like '*" & Me.txtAreaFilter & "*'" & " and TourOrganiserID =" & Nz(Me.cmbTourOrganiser, [TourOrganiserID])
    Me.FilterOn = True
    however I get mixed results

    instead of showing all the results if I type say an area "NSW" I show only one of the organizers instead of all the organizers.

    The same action would happen on an after update event with the combo box

  5. #5
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I am using

    Code:
    If IsNull(Me.cmbNameFilter) Then
    Me.Filter = "[Area] Like '*" & Me.txtAreaFilter & "*'"
    Me.FilterOn = True
    Else
    Me.Filter = "[Area] Like '*" & Me.txtAreaFilter & "*'" & " and TourOrganiserID =" & Me.cmbNameFilter
    Me.FilterOn = True
    End If
    to get around this but I would like to know if there is a better way

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Not really - but this is an option:
    Me.Filter = "[Area] Like '*" & Me.txtAreaFilter & "*'" & IIf(Not IsNull(Me.cmbNameFilter), " and TourOrganiserID=" & Me.cmbNameFilter, "")
    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.

  7. #7
    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
    Not really - but this is an option:
    Me.Filter = "[Area] Like '*" & Me.txtAreaFilter & "*'" & IIf(Not IsNull(Me.cmbNameFilter), " and TourOrganiserID=" & Me.cmbNameFilter, "")
    It all works ok - even the button to filter non nulls to show only the nulls in a particular field - however on the afterupdate of the combo boxes it filters to null when I only want to to filter if the button has a certain caption

    I am using

    Code:
    Me.Filter = "[Area] Like '*" & Me.Text36 & "*'" & IIf(Not IsNull(Me.Text38), " and SchoolTypeID=" & Me.Text38, "") & IIf(Not IsNull(Me.txtStates), " and StateID=" & Me.txtStates, "") & IIf(Me.Command47.Caption = "Blank Emails", "and SchoolEmail is Null", "")
    Me.FilterOn = True
    The problem occurs when you change SchoolType it filters the form to show null emails even when the button caption is on "Show All"

  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 Ruegen View Post
    It all works ok - even the button to filter non nulls to show only the nulls in a particular field - however on the afterupdate of the combo boxes it filters to null when I only want to to filter if the button has a certain caption

    I am using

    Code:
    Me.Filter = "[Area] Like '*" & Me.Text36 & "*'" & IIf(Not IsNull(Me.Text38), " and SchoolTypeID=" & Me.Text38, "") & IIf(Not IsNull(Me.txtStates), " and StateID=" & Me.txtStates, "") & IIf(Me.Command47.Caption = "Blank Emails", "and SchoolEmail is Null", "")
    Me.FilterOn = True
    The problem occurs when you change SchoolType it filters the form to show null emails even when the button caption is on "Show All"
    nevermind I swapped Blank Emails with Show All - my dufus brain.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    You might find this interesting. The following criteria for a number field in a query works:

    LIKE "*" & [input value] & "*"

    I tested on a number field with year values (2012, 2013, 2014). I entered 14 as the parameter and all the 2014 records returned.
    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
    You might find this interesting. The following criteria for a number field in a query works:

    LIKE "*" & [input value] & "*"

    I tested on a number field with year values (2012, 2013, 2014). I entered 14 as the parameter and all the 2014 records returned.
    cheers thanks

    I'm re-designing a few forms to VBA filters rather than record source criteria that lead to forms although I don't know if there is an improvement to speed (if I am not having to requery then maybe? - but I assume filterOn = true requeries anyway)

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

Similar Threads

  1. Replies: 1
    Last Post: 08-16-2012, 01:51 PM
  2. Another Search Filter Question
    By r0v3rT3N in forum Programming
    Replies: 4
    Last Post: 07-23-2012, 12:20 PM
  3. Form Filter Question
    By anunat in forum Forms
    Replies: 3
    Last Post: 06-27-2012, 09:17 PM
  4. Replies: 28
    Last Post: 03-08-2012, 06:47 PM
  5. Text Box Filter Question
    By ShadeRF in forum Forms
    Replies: 4
    Last Post: 06-07-2011, 07: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