Results 1 to 10 of 10
  1. #1
    Varda is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    44

    Filter main form based on subform data

    Re: https://www.accessforums.net/forms/f...orm-49326.html



    I have a similar question to the original poster.

    The response given on this thread is not very clear to me.
    Last edited by June7; 01-02-2015 at 04:25 PM.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    What about the suggested options do you feel need clarification? I will try to do so.
    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
    Varda is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    44
    I have a Main Form and a Subform, and I need to filter by two criteria.

    One criterion is on the Subform, and the other criterion is on the Main Form.

    The code I'm using to filter the subform isn't working for me, and the suggestions online end up like the original poster said - it shows ALL records on the Main Form regardless of whether the subform has the filtered value or not.

    The examples I found online deal with a Text type field, and my example is a Number type field. I believe I adjusted it properly, but it's still not working right.

    My Main Form has a combo box to search for the value I want to filter the subform by, and here's the code:

    Code:
    strTypeID = Me.cboTypeID.Value
    strFilter = "Forms![MainForm]![SubForm].Form![TypeID]=" & strTypeID
    
    With Forms!MainForm
            .Filter = strFilter
            .FilterOn = True
        End With

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Filtering the subform has nothing to do with filtering the main form (children don't dictate to parents).

    Looks like you need to use both techniques suggested.
    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.

  5. #5
    Varda is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    44
    FilteringSubform.zip

    I'm uploading my database to show the issue I have.

    I've placed both filtering options suggested: Combo box and List Box. Neither works for me.

    I know the issue is with the code I placed in the "After Update" of the "Apply Filter" command button. I'm just not sure how to change it to make it work.

    I am not sure I understand "children don't dictate to parents." I'm trying to find all the parents that have male children - isn't this a valid question to ask in a main form?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I mean the subform (the child) does not dictate filter of main form (the parent). The reverse is true. The subform will show only those records that are associated with the record on the main form.

    These tables have many-to-many relationship. Including tblReportItems in the main form RecordSource will cause repetition of the tblItems data when there are multiple related records in tblReportItems. This is not appropriate for a form/subform data entry arrangement. ItemID should not be a combobox on the subform. ItemID is the Master/Child link between the forms. It should not be editable on the subform. Shouldn't even be visible there.

    Maybe you should consider the subform as an independent form. Set up as Continuous form and put the filtering controls into its header section.
    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.

  7. #7
    Varda is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    44
    The database I uploaded is a shortened version of the database I have. I did it a bit rushed and didn't check to make sure it reflects everything the way I designed it. Though I'm a bit baffled by some of the issues you raise because I don't see them on my version of the database. (I'm using MS Access 2010).

    ItemID is not editable on the subform and does not show on it in my version.

    The Form-Subform relationship is ideal for this particular many-to-many relationship.

    Every Item can be identified with possibly just a Weekly Status Report, or Weekly Status Report and Monthly Report and Leadership Report.
    Each one of these type of reports can be associated with multiple items.

    There should be no repetition of tblItems data.


    I'm confused about your suggestion to make the subform an independent form. I need to create the filter on a Data Entry form, not in a continuous form.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Data entry can be done in a Continuous form. A Continuous form can be made to look like Datasheet. However, up and down cursor keys don't seem to work.

    You should add multiple records associated with an Item then requery the form and see what happens. I added a Leadership Report for ItemID 1 along with the Weekly Status Report record and requeried the form. Now there are 2 ItemID 1 records on the main form.

    You're right, ItemID combobox is not showing even though it is in Design View and it is set to be Visible. Same for Reports_ItemsID textbox. They have been set as hidden in form view. A user could unhide them. There is no reason to include these controls on the form.
    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.

  9. #9
    Varda is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    44
    I found out the issue and why you're seeing double (and it's not the New Year alcohol that's doing it). When I re-created the database, I based it on the wrong query. I fixed it and am re-uploading the database to properly reflect what I have in the larger version.

    the issue with resolving this with a continuous form is that my original database has a LOT of data entry fields, and a couple of them are of the Memo type, which necessitates as much screen real estate as possible per item. A continous form would annoy the end-user tremendously.

    I made the combo box on the subform invisible. Hopefully this would resolve the issue. The reason I included them on the subform is because I wasn't sure why my filtering code wasn't working and figured it's best to place them on the subform so the filter works.


    I'm trying to do a work-around and filter the main form only by Status, and then filter by three check marked fields. But I'm having trouble even with that feature. I will likely post a new post entirely, as it is no longer relevant to the original post here.
    Attached Files Attached Files

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    This subform doesn't have memo fields, so that is irrelevant. Why would a continuous form that looks like datasheet be annoying - aside from the lack of up/down cursor movement?

    You have lookups with alias in table. Advise against this unless you really understand what is happening. Review: http://access.mvps.org/access/lookupfields.htm

    Why are you having trouble with the filtering, what happens - error message, wrong results, nothing?

    Appear to be missing = sign for: strStatus = "='Closed'"
    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.

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

Similar Threads

  1. filter main form base on subform data
    By ss3373 in forum Access
    Replies: 7
    Last Post: 06-24-2011, 09:21 PM
  2. Subform Filter based on Main Form Information
    By james.carpenter2 in forum Forms
    Replies: 0
    Last Post: 02-16-2011, 09:55 PM
  3. Replies: 1
    Last Post: 11-16-2010, 08:42 AM
  4. Replies: 2
    Last Post: 06-17-2010, 04:15 PM
  5. Replies: 1
    Last Post: 06-14-2010, 02:31 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