Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2004
    Location
    UK
    Posts
    246

    Unanswered: ApplyFilter not working

    Hi,
    I have a continuous form that has 4 combo boxes and a command button in the header section. Once the user has made a selection from all 4 combo boxes the command button is made visible. This command button has the OnClick event activated with the following code

    Private Sub Filterfind_Click()
    DoCmd.ApplyFilter "Interest_frm_flr"
    End Sub

    Unfortunately this is not applying the filter criteria, in fact no filter al all is being applied.
    However if I use the advanced filter option and load from query and then apply it, all is well.

    Not sure what I'm doing wrong, anyone any idea's?

    Regards
    John

  2. #2
    Join Date
    Dec 2002
    Posts
    60

    Re: ApplyFilter not working

    Originally posted by Sticker
    Hi,
    I have a continuous form that has 4 combo boxes and a command button in the header section. Once the user has made a selection from all 4 combo boxes the command button is made visible. This command button has the OnClick event activated with the following code

    Private Sub Filterfind_Click()
    DoCmd.ApplyFilter "Interest_frm_flr"
    End Sub

    Unfortunately this is not applying the filter criteria, in fact no filter al all is being applied.
    However if I use the advanced filter option and load from query and then apply it, all is well.

    Not sure what I'm doing wrong, anyone any idea's?

    Regards
    John
    Try:

    Private Sub Filterfind_Click()
    DoCmd.ApplyFilter "Interest_frm_flr"
    Me.FilterOn=True
    End Sub

  3. #3
    Join Date
    Feb 2004
    Location
    UK
    Posts
    246
    Hi,
    Thanks for the response, but unfortunately no change, still no filter being applied.

    Regards
    John

  4. #4
    Join Date
    Dec 2002
    Posts
    60

    Re: ApplyFilter not working

    Originally posted by bc301
    Try:

    Private Sub Filterfind_Click()
    DoCmd.ApplyFilter "Interest_frm_flr"
    Me.FilterOn=True
    End Sub
    OK... is the form property AllowFilters = Yes? and maybe do a requery after applying (Me.Requery). Just guessing.

  5. #5
    Join Date
    Feb 2004
    Location
    UK
    Posts
    246
    Thanks again for the reply

    Alllow filters are set to yes and I've included the requery in code but still the filter is not being applied

    Regards
    John

  6. #6
    Join Date
    Nov 2003
    Location
    Warren, PA
    Posts
    52

    Re: ApplyFilter not working

    You need to tell what field to filter and criteria, you said four combo so your filter will look something like this:

    Me.Filter = "fieltofilter1 = '" & Combo1 & "' And fieltofilter2 = '" & Combo2 & "'" And fieltofilter3 = '" & Combo3 & "'" And fieltofilter4 = '" & Combo4 & "'"
    Me.FilterOn = True


    Brent

  7. #7
    Join Date
    Feb 2004
    Location
    UK
    Posts
    246
    Hi Brent thanks for the suggestion

    I'm not sure that I follow your meaning.
    At present the 4 combo boxes feed a query and this query is the filter that I'm trying to apply. This query holds all the varible AND/OR combinations for the combo boxes. What I don't understand is that by loading the query manually and apply this as the filter it all works but calling the filter from code doesn't.

    Are you saying that I have to declare all the variables in code?

    Regards
    John

  8. #8
    Join Date
    Nov 2003
    Location
    Warren, PA
    Posts
    52
    Ok then this

    For one combo box:
    DoCmd.SelectObject acQuery, "Queryname", False
    DoCmd.ApplyFilter "", "[Queryname]![Queryfield]='" & Comboboxname & "'"

    For four:
    DoCmd.SelectObject acQuery, "Queryname", False
    DoCmd.ApplyFilter "", "[Queryname]![Queryfield]='" & Comboboxname & "' and "[Queryname]![Queryfield2]='" & Combobox2name & "' and "[Queryname]![Queryfield3]='" & Combobox3name & "' and "[Queryname]![Queryfield4]='" & Combobox4name & "'"

    Try that
    Brent
    Last edited by bhummel; 04-22-04 at 13:31.

Posting Permissions

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