Results 1 to 6 of 6
  1. #1
    Sue22's Avatar
    Sue22 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    15

    Apply a filter using values in one of two fields on a form

    Hi there:


    I created a form which I want users to be able to filter using a value entered into an unbound text box (txtSearchP) on the form.
    Once the user has entered the search text then the idea is they click on the flitter button (cmdSearchP) on the form I want the results to be filtered based on the Values in two fields [Programme] or [Programme_Desc] so that the filtered results show records where either of these fields contains the search term (txtSearchP).

    I can get this to work if I search just one field using the code below:

    Private Sub cmdSearchP_Click()
    ' Filter by Programme Description
    Me.Filter = Me.Filter = "[Programme_Desc] Like " & Chr(34) & "*" & Me.txtSearchP & "*" & Chr(34)
    Me.FilterOn = True
    Me.Requery
    End Sub

    This works fine but when I try to search for the value in either filed I either end up with error messages or it appears to work but brings back nothing or brings back all records depending on what I put in.
    Can anyone help I have been banging my head against the wall for ages with this now I've 'googled' and can't find anything helpful that I could understand. The odd few examples I found and tried didn't work.
    I know I could give the users two separate text boxes and Buttons and force then to search either by code of description but I don't want the form to be cluttered and it needs to be idiot proof.

    Thanks in advance


  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,726
    Untested, but I'd try

    Me.Filter = [Programme_Desc] Like "*" & Me.txtSearchP & "*" OR _
    & [Programme] Like "*" & Me.txtSearchP & "*"

  3. #3
    Sue22's Avatar
    Sue22 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    15
    Tried that and just got error messages

  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,726
    It would be nice if you told us the message number or text.

    Again, untested, but the filter expression should be a string.

    Try
    Code:
    Me.Filter = "[Programme_Desc] Like '*" & Me.txtSearchP & "*' OR " _
    & "[Programme] Like '*" & Me.txtSearchP & "*'"

  5. #5
    Sue22's Avatar
    Sue22 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    15
    Thant worked a treat Thank you so much

  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,726

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

Similar Threads

  1. Filter By Form and Apply Filter Buttons
    By JustLearning in forum Forms
    Replies: 13
    Last Post: 02-18-2015, 01:01 PM
  2. Replies: 9
    Last Post: 08-05-2014, 03:09 PM
  3. Macro to apply filter to form
    By mattzkn in forum Macros
    Replies: 3
    Last Post: 12-11-2013, 12:57 AM
  4. Replies: 2
    Last Post: 02-25-2013, 10:47 AM
  5. Replies: 5
    Last Post: 02-07-2013, 12:21 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