Filtering Subform with Toggle Buttons

doubleohkevin

New member
Local time
Today, 12:45
Joined
Sep 25, 2014
Messages
5
I have a tab control at the bottom of my main form, and some of the tab pages contain subforms. On one of the subforms I have created a filter to divide the content into "complete" and "incomplete." I have also added a toggle button option group to the subform to toggle the filter (one button for "complete" and one for "incomplete"). I'm using a macro to apply the filter, but it isn't working. The filter does work properly if I use the "Toggle Filter" button on the Ribbon, but I want to create something a little more user friendly.

I have:
  • Main form: Search_by_name
  • Subform: Action_Items
  • Underlying table: tbl_Action_Items
  • Subform control: sfctlActionItems
  • Toggle button option group: tgl_Complete_Incomplete

Here's the macro as it stands right now:
If [tgl_Complete_Incomplete]=-1 Then
ApplyFilter
Filter Name
Where Condition =(([tbl_Action_Items].[Completed])=True)
Control Name [Forms]![Search_by_name]![sfctlActionItems].[Form]![tgl_Complete_Incomplete]
Else
RunMenuCommand
Command RemoveFilterSort
End If


I get the error message "The 'ApplyFilter' action requires a valid control name that corresponds to a subform or subreport."

If I remove the content of the Control Name field and open the subform independently (i.e. not as a subform), everything works fine.

Also, I understand that VBA is a better option than using a macro, but unfortunately I don't really have time to learn VBA for this.
 
It's normally wise to give it what it wants: "a valid control name that corresponds to a subform or subreport". You didn't.
 
OK, so where did I go wrong? I had thought the line [Forms]![Search_by_name]![sfctlActionItems].[Form]![tgl_Complete_Incomplete] was referencing the control on the subform, but I guess I'm off base.

Sorry, I'm learning Access as I go here, and I can't find much help online for my problem. Everything I've found so far has seemed to suggest I needed to construct my control name as above.
 
That's the problem: I'm not sure what it wants. I know I need a valid control name, but I don't know the proper way to construct it.

From what I've been reading online, it sounded like I needed to reference the control within the subform (referencing the subform control on the main form to get to the subform) using the full path. But obviously there's something I'm not getting right. I've tried several variations on the control name (with and without the control within the subform), but nothing seems to work.
 
Last edited:
OK, so I took your advice and took a closer read of what it wants. I had been trying to reference the control within the subform, but am I right in thinking that I should instead reference only the control that contains the subform? If that's the case, I've tried [Forms]![Search_by_name]![sfctlActionItems] but I'm still getting the same error.
 
Someone ended up pointing me to a solution with a nice simple bit of VBA:
Code:
If Me.tgl_Complete_Incomplete = -1 Then
    Me.Filter = "[Completed]=-1"
    Me.FilterOn = True
  ElseIf Me.tgl_Complete_Incomplete = 0 Then
    Me.Filter = "[Completed]=0"
    Me.FilterOn = True
  Else
    Me.FilterOn = False
End If
 

Users who are viewing this thread

Back
Top Bottom