• Filter won’t work on a subform (2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Filter won’t work on a subform (2000)

    Author
    Topic
    #373628

    The problem:

    frmSearchForm builds a filter called stLinkCriteria. A button on frmSearchForm opens frmSearchResults to display the found records.

    A button on frmSearchResults opens frmCCU that includes frmSearchResults as subform on a Tab called “SEARCH RESULTS”. (I am leaving frmSearchResults open.)

    In my efforts to get the subform to apply the filter, the OnLoad event for frmCCU includes:

    dim stLinkCriteria as String
    stLinkCriteria = Forms![frmSearchResults].Filter
    Debug.Print stLinkCriteria ‘stLinkCriteria is populating with the filter
    [subSearchResults].SetFocus ‘try putting focus on the sub report before applying filter
    DoCmd.ApplyFilter stLinkCriteria

    If anyone can point out the error of my ways, I’d greatly appreciate it.

    Thanks,

    Randy

    Viewing 0 reply threads
    Author
    Replies
    • #601181

      (1) ApplyFilter has 2 arguments: FilterName and WhereCondition. FilterName is the name of a stored filter query. If you don’t want to use this, you must either place a comma before the WhereCondition or use named arguments:

      DoCmd.ApplyFilter , stLinkCriteria

      or

      DoCmd.ApplyFilter WhereCondition:=stLinkCriteria

      (2) I’ve had problems with ApplyFilter in Access 97 – sometimes it fails to do anything without raising an error. So I suggest setting the Filter and FilterOn properties instead:

      With [subSearchResults].Form
      .Filter = stLinkCriteria
      .FilterOn = True
      End With

      • #601186

        Hans –

        I sure spent a lot of time going around in circles with this. I took your advice and used
        With [subSearchResults].Form
        .Filter = stLinkCriteria
        .FilterOn = True
        End With

        and it now works fine.

        Thank you very much for your help with this. Maybe now my hair can start to grow back.

        Randy

    Viewing 0 reply threads
    Reply To: Filter won’t work on a subform (2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: