Results 1 to 3 of 3
  1. #1
    TheChrisLV is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    4

    Use VBA to apply a filter to the main form only (i.e. not apply filter to subforms)

    Hello,



    I have a form where I have users enter text into a text box then press a button that filters the form based on the text entered into the box. When the user presses the button, the filter is applied as expected but the filter is also being applied to the subform which is not intended. To "fix" this I use the following code to turn off the filter on the subform.

    Private Sub TFilterBtn_Click()
    Me.Filter = "[DocumentTitle] LIKE" & Chr(34) & "*" & TitleFilterbx.Value & "*" & Chr(34)
    Me.FilterOn = True
    With RevisionSubF.Form
    '.Filter = vbNullString
    .FilterOn = False
    .OrderBy = "[RevisionSubF].[Superseeded] DESC"
    .OrderByOn = True
    End With

    Me.Requery

    End Sub

    Is there a way to only have the FilterOn = True apply to the main form and not the subform so that I don't have to use code to clear the filter for every subform and redefine the OrderBy which gets cleared during the process?

    Thanks in advance.

  2. #2
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    you can do that as long as you don't have master and child relationships to any of your subforms..

    you are not setting the filter on here anyway..
    With RevisionSubF.Form
    '.Filter = vbNullString
    .FilterOn = False
    .OrderBy = "[RevisionSubF].[Superseeded] DESC"
    .OrderByOn = True
    End With

  3. #3
    TheChrisLV is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    4
    Thanks for the reply. I had to turn off the filter on the subform (.FilterOn = False) because setting the filter for the main form was also setting the filter for my subforms which I did not want filtered. I was ok with having to code turning off the filter for the subforms but I hate that whatever sorting I had applied to the subform was also cleared and I have to reset the .OrderBy expression

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

Similar Threads

  1. Filter By Form and Apply Filter Buttons
    By JustLearning in forum Forms
    Replies: 13
    Last Post: 02-18-2015, 01:01 PM
  2. Replies: 5
    Last Post: 02-07-2013, 12:21 PM
  3. Apply Filter similar to Field Filter
    By DatabaseIntern in forum Forms
    Replies: 1
    Last Post: 06-11-2012, 05:42 PM
  4. How to filter dates using an apply filter code.
    By Jgreenfield in forum Reports
    Replies: 4
    Last Post: 11-15-2011, 01:38 PM
  5. Apply filter command
    By miziri in forum Forms
    Replies: 6
    Last Post: 01-21-2010, 02:22 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