Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Maine, USA
    Posts
    258
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Filter a subform (97)

    I am trying to use buttons to filter a subform.

    The subform [frmIndicatorDetailsSub] is linked to the main form [frmClients] by the field ClientID. I want to use buttons to filter the field QuarterID on the subform. I already have an unbound field on the main form which updates based on which button is clicked.

    I tried to follow the directions for doing this on a post on the Access Web , but am still stumped. I have limited understanding of code, so I couldn't completely follow what they were suggesting, and tried to accomplish their alternate suggestion of using a predefined query (I'm assuming this means build the query in the "query" tab of the Database window).

    I successfully created a query [qryChooseQuarter] which does bring up the data, correctly filtered, when [frmClients] is open. But all my efforts to follow their syntax to get the button to apply the query to the subform have failed. I may be missing something, or maybe it is because of the version of Access I am working in (I found that link based on a question on this board from someone using 2000). I'm not wedded to their syntax. Anything that will work will make me happy.

    Hoping to get over this hump! Thank you in advance,
    -cynthia

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Filter a subform (97)

    Try something like the following:

    Private Sub cmdFilter_Click()
    Me.frmIndicatorDetailsSub.Form.RecordSource = "qryChooseQuarter"
    End Sub

    Attached to <post#=132267>post 132267</post#> you will find a demo Access 97 database that uses combo boxes to filter a subform. If you look at the code behind frmDemo, you will see how the record source of the subform is being changed.

  3. #3
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Maine, USA
    Posts
    258
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filter a subform (97)

    Thank you. That does it.
    Following the example on Access Web, I had used a ! after the Me, and I did not have quotation marks around my "qryChooseQuarter".

    But I'll pat myself on the back for at least having picked the right line from their code to use for syntax!
    Thanks for getting me over the hump. And thanks for the reference to the sample database. I've been advised elsewhere on this board that I should be using filters where I am currently using bookmarks, so it's something I need to understand.
    -cynthia

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Filter a subform (97)

    Hi Cynthia,

    I'm glad you got that sorted out.

    Bookmarks are often used to locate a specific record within a form, while leaving all records visible. Filters are used to limit the records that are displayed to those satisfying a certain condition, and changing the record source can be used for the same purpose. The latter method has the advantage that the user can't cancel the filter by accident.

  5. #5
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Maine, USA
    Posts
    258
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filter a subform (97)

    Thank you again. That is a very nicley clear description of the difference.
    -c

Posting Permissions

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