Filtering Forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rosy

    Filtering Forms

    I need to have a form filter from two differnt fields.

    First the user needs to be able to pick from a list of categories.
    Then the user needs to be able to choose a size from the results of
    the category.

    If i set the parameters in the query, then they can't choose from the
    list.

    This is what I came up with, but when you use the second drop down
    box, it doesn't pull from just teh results of the first box.

    Private Sub Combo1_Change()
    Dim strFilter
    strFilter = "[VesselCategory]=""" & Combo1.Text & """"
    Form_AllJobs.Vi sible = True
    Form_AllJobs.Fi lter = strFilter
    Form_AllJobs.Fi lterOn = True
    Form_AllJobs.Re fresh
    End Sub



    Private Sub Combo32_Change( )
    Dim strFilter
    strFilter = "[Vesselsizerange]=""" & Combo32.Text & """"
    Form_AllJobs.Vi sible = True
    Form_AllJobs.Fi lter = strFilter
    Form_AllJobs.Fi lterOn = True
    Form_AllJobs.Re fresh
    End Sub
  • Salad

    #2
    Re: Filtering Forms

    Rosy wrote:
    I need to have a form filter from two differnt fields.
    >
    First the user needs to be able to pick from a list of categories.
    Then the user needs to be able to choose a size from the results of
    the category.
    >
    If i set the parameters in the query, then they can't choose from the
    list.
    >
    This is what I came up with, but when you use the second drop down
    box, it doesn't pull from just teh results of the first box.
    >
    Private Sub Combo1_Change()
    Dim strFilter
    strFilter = "[VesselCategory]=""" & Combo1.Text & """"
    Form_AllJobs.Vi sible = True
    Form_AllJobs.Fi lter = strFilter
    Form_AllJobs.Fi lterOn = True
    Form_AllJobs.Re fresh
    End Sub
    >
    >
    >
    Private Sub Combo32_Change( )
    Dim strFilter
    strFilter = "[Vesselsizerange]=""" & Combo32.Text & """"
    Form_AllJobs.Vi sible = True
    Form_AllJobs.Fi lter = strFilter
    Form_AllJobs.Fi lterOn = True
    Form_AllJobs.Re fresh
    End Sub
    I sometimes do something like this. First, I use the AfterUpdate event
    but it probably doesn't make any difference...I just like to have it
    make it past the NotInList event or any error routines that may exist
    before setting the filter.

    Private Sub Combo1_AfterUpd ate()
    'refresh the list in combo 32 to associate with Combo1
    Me.Combo32.Requ ery
    SetFilter
    ENd Sub
    Private Sub Combo32_AfterUp date()
    SetFilter
    ENd Sub
    Private Sub SetFilter()
    Dim strFilter
    IF Not IsNull(Me.Combo 1) then
    strFilter = "[VesselCategory]='" & Me.Combo1 & "' And "
    IF Not IsNull(Me.Combo 32) then
    strFilter = strFilter & _
    "[Vesselsizerange]='" & Combo32 & "' And "
    Endif
    Endif
    If strFilter "" THen
    'remove the "And"
    strFilter = _
    Left(strFilter, len(strFilter)-5)
    Endif
    Form_AllJobs.Fi lter = strFilter
    Form_AllJobs.Fi lterOn = (strFilter "")
    End Sub

    BristleBot Cat Toy

    Comment

    • Harry Skelton

      #3
      Re: Filtering Forms

      On Fri, 18 Apr 2008 08:27:08 -0700, Rosy wrote:
      First the user needs to be able to pick from a list of categories. Then
      the user needs to be able to choose a size from the results of the
      category.
      I usually use an OnExit event on the first field to reset the
      RecordSource of the second field to the new query that I would build.
      You could filter, but I have found that filters can be affected by too
      many other things. Setting an new query string would resolve the problem
      and limit the list to only the items listed in the query.

      If you want a caption as the first list item, then you will have to run
      the query by program and load the listbox with your values.

      Comment

      Working...