Results 1 to 8 of 8
  1. #1
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160

    how do I filter 2 subforms?

    Hi, I'm trying to search/filter 2 subforms on the main form, this is the code:



    Code:
    Private Sub btnSearch_Click()
    Dim MempSQL As String
    Dim BercSQL As String
    MempSQL = "SELECT Complaint, ComplaintEdited, " _
          & "Preparation, PreparationEdited, " _
          & "Administration, AdministrationEdited, " _
          & "PartUsed, TimesRecorded, Healer, " _
          & "SpeciesID, ComplaintID, FloraPalComplaintID " _
          & "FROM MempComplaintTom " _
          & "Where Complaint LIKE '*" & Me.txtSearch & "*';"
    Me.MempComplaintSubFrm.Form.RecordSource = MempSQL
    Me.MempComplaintSubFrm.Form.Requery
    
    
    BercSQL = "SELECT SpeciesID, ComplaintID, System, Complaint, TimesRecorded, " _
            & "PartsUsed, Preparation, Administration, InformationSource, ScientificStudies " _
            & "FROM BercComplaints " _
            & "Where Complaint LIKE '*" & Me.txtSearch & "*';"
    Me.BercComplaintsSF.Form.RecordSource = BercSQL
    Me.BercComplaintsSF.Form.Requery
    End Sub
    The strange thing is only the first filter works, and if comment out one of the queries the other will work.

    Can anyone explain to me what's going on, and how I can fix it.

    Thanks
    David

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Do you get an error, or it just doesn't filter? If you comment out the first, the second starts working?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi Paul, very much appreciate if you could take a look at the attached db. I was mistaken, it's the second subform - BercComplaintsSF - that stops working, as soon as you use the Search Complaints it turns blank.

    Thanks
    David
    Attached Files Attached Files

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Something weird is going on. The master/child links are what prevent the form from showing the results. I delete them and they come back. You can try a decompile to see if that fixes the problem, but this works as a workaround:

    Me.BercComplaintsSF.LinkMasterFields = ""
    Me.BercComplaintsSF.LinkChildFields = ""
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Thanks very much for taking the time to look at this

    Where should I put

    Me.BercComplaintsSF.LinkMasterFields = ""
    Me.BercComplaintsSF.LinkChildFields = ""



  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I think I had them after the line setting the record source.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi,
    Today I decided to build the main form and subforms from new, but it didn't help still the same problem.
    The difference between the subform that works and the one that doesn't is the working subform LinkMasterField is the primary key and the LinkMasterField of the subform that's not working is not a PK. On inspection I discovered that the value of the LinkMasterKey of the subform that's not working gets changed to the working subform's LinkMasterKey which results in it not returning any records.
    In addition to these problems all the tables connected to this form have lost their primary keys - all the data is ok. Do you have any explanation for these problems?

    Thanks
    David

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No, it seemed the link values were repopulating themselves, which I've never had happen before.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Need filter(s) on subforms of nav form to synch
    By kattatonic1 in forum Forms
    Replies: 6
    Last Post: 03-21-2017, 07:14 AM
  2. Subforms Inside Subforms
    By LordPanzer in forum Access
    Replies: 1
    Last Post: 10-11-2013, 05:19 PM
  3. Replies: 2
    Last Post: 02-25-2013, 10:47 AM
  4. Can you filter two subforms at the same time?
    By haggis999 in forum Forms
    Replies: 17
    Last Post: 12-30-2012, 04:06 AM
  5. Continuous Subforms Filter Dependant Combo
    By BigBear in forum Forms
    Replies: 0
    Last Post: 04-19-2009, 08:13 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