Results 1 to 5 of 5
  1. #1
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110

    Filtering

    I have a main form. It has a sub form and a sub report.



    The main form is a Single Form
    The sub form is Continuous Form
    The Sub Report is a Report.

    The main form Primary Key links to the Sub Form Foreign Key.

    The Sub Report is based on a query that creates the sub form.

    I want a user to click a field on the sub form and the sub report displays filtered results.

    Can someone walk me through the VBA to do this please?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    See if this example helps. If you need more help, provide your attempted code or attach your db for analysis.

    Private Sub tbxUmpID_Click()
    Me.Parent.ctrComp.Report.FilterOn = False
    Me.Parent.ctrComp.Report.Filter = "UmpID = " & Me.UmpID
    Me.Parent.ctrComp.Report.FilterOn = True
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Join Date
    Jan 2021
    Location
    Missouri Ozarks, USA
    Posts
    19
    Clarifying question: Are you trying to filter the table/query behind the sub form based on values in the parent form? If so, I would typically use an unbound field in the form and execute an event "On enter" that queries the data behind the sub form using the unbound field as a parameter in the query. There isn't much VBA required. Just a DoCmd.RunQuery "qry_myParameterQuery" and include the unbound control as a parameter in your query.

  4. #4
    Join Date
    Jan 2021
    Location
    Missouri Ozarks, USA
    Posts
    19

    Link to more info

    In the approach I described, the parent form is unbound. This technique is described in the detail here:
    https://www.oreilly.com/library/view/access-cookbook/0596000847/ch01s02.html
    Last edited by canyonraven; 06-11-2022 at 10:01 PM. Reason: Including a reference

  5. #5
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110
    Hi June

    I kept getting a runtime error with the code you provided as an example, so I amended it to just an on click even with the
    Me.Parent.ctrComp.Report.Filter = "UmpID = " & Me.UmpID (customised)
    This works and I can click record after record and have no issue and no runtime.

    Thank you.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Filtering
    By birdie2020 in forum Queries
    Replies: 4
    Last Post: 08-10-2020, 10:51 AM
  2. Filtering for
    By Calhoontuna in forum Access
    Replies: 9
    Last Post: 05-14-2019, 09:54 AM
  3. Yes/No filtering
    By cgalvin in forum Reports
    Replies: 1
    Last Post: 05-11-2015, 05:59 PM
  4. Filtering
    By BannedOak in forum Access
    Replies: 9
    Last Post: 05-22-2011, 02:10 PM
  5. filtering
    By nashr1928 in forum Forms
    Replies: 12
    Last Post: 07-01-2010, 06:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums