Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2009
    Posts
    1

    Post Unanswered: Using a combo box to filter records on an access form

    I'm attempting to filter records on my form based on the drop down values of a combo box. However, I'm trying to filter the records of two different fields based on the value in a single combo box. Both fields (Site_A) and (Site_B) contain the same type of data and the value that I choose in my combo box may appear in either field. The following code allows me to sucessfully filter based upon of the two fields:

    Private Sub FilterBySiteNameCombo_AfterUpdate()

    Me.Filter = "(Site_A) = '" & Me.FilterBySiteNameCombo & "'"
    Me.FilterOn = True

    End Sub

    However, I'd like to add (Site_B) to the mix so that the form records will be filtered when the value I choose in the combo box appears in either or both the (Site_A) and (Site_B) fields. I'm very new to visual basic but it seems like I'm probably just overlooking something simple. Is there a simple "and/or" like function I can add to the above code?


  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Having 2 fields indicates a design problem, but

    Me.Filter = "(Site_A) = '" & Me.FilterBySiteNameCombo & "' OR (Site_B) = '" & Me.FilterBySiteNameCombo & "'"
    Paul

  3. #3
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Or even what pbaldy said ^^
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  4. #4
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Code:
    Private Sub FilterBySiteNameCombo_AfterUpdate()
       Me.Filter = "(Site_A) = '" & Me.FilterBySiteNameCombo & "'  OR (Site_A) = '" & Me.FilterBySiteNameCombo & "'""
       Me.FilterOn = True
    End Sub
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  5. #5
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Now THAT is weird. I posted the last two posts in reverse order -- posts 3 and 4 have their times mixed up or something. This site is a bit shaky ^^
    Last edited by StarTrekker; 04-28-09 at 02:02.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •