Results 1 to 7 of 7
  1. #1
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314

    Filter continuous forms with value from a Combo Box

    I need to be able to filter a continuous form based on a value in a combo box. The code below does not work. How can I fix it to make it work? I suppose the issue is related to using quotes in the Me.Filter = expression, but I don't understand when and how to use quotes in certain kinds of expressions, such as this.


    Code:
    Private Sub cbo_FilterOn_AfterUpdate()
    If IsNull(Me.cbo_FilterOn) Then
      Me.Filter = ""
      Me.FilterOn = False
    Else
      Me.Filter = InStr[Comment], cbo_FilterOn)
      Me.FilterOn = True
    End If
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Probably

    Me.Filter = "[Comment] Like '*" & Me.cbo_FilterOn & "*'"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    Thank you. That works!

  4. #4
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    Never mind the question about the single quote. After further thought, I understand.

    I guess the control did not actually need to be a combo box. It could have been a simple unbound text box.

    How can I modify the expression to search two fields, [Comment] and [Vendor]? If I enter a vendor name, it will not likely find that value in [Comment] field and vice-a-versa.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    When I have multiple/optional search fields, I tend to use dynamic SQL and build up a string that includes any values entered. Jason demonstrates it in the sample db here:

    http://www.baldyweb.com/BuildSQL.htm

    You can use it for the filter too.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    As I was looking at your suggestion, it occurred to me I might try to use an OR in the expression such as:
    Code:
    Private Sub cbo_FilterOn_AfterUpdate()
    If IsNull(Me.cbo_FilterOn) Then
      Me.Filter = ""
      Me.FilterOn = False
    Else
      Me.Filter = "[Comment] Like '*" & Me.cbo_FilterOn & "*'" & " OR " & "[Vender] Like '*" & Me.cbo_FilterOn & "*'"
      Me.FilterOn = True
    End If
    End Sub
    And this works too. [I know, I misspelled "Vendor" when I originally named the field.]
    Thanks again for your help.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Glad you got it working.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Filter Continuous Forms by Combobox
    By zozzz in forum Forms
    Replies: 7
    Last Post: 08-07-2017, 08:57 AM
  2. Creating a filter for continuous forms
    By NJMike64 in forum Macros
    Replies: 2
    Last Post: 02-17-2016, 10:44 AM
  3. Filter continuous form by combo box
    By revolution9540 in forum Forms
    Replies: 10
    Last Post: 08-04-2015, 02:16 PM
  4. Filter a continuous form using a combo box
    By Chky071 in forum Access
    Replies: 5
    Last Post: 05-04-2015, 08:06 AM
  5. Replies: 1
    Last Post: 11-24-2011, 07:45 AM

Tags for this Thread

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