Hiding a subform in a tab based on a list selection (1 Viewer)

fresnel4

New member
Local time
Today, 12:36
Joined
Feb 17, 2019
Messages
3
After many attempts I am finally needing help with this...

I have a mainform with a listbox of names and what program they belong to. I also have a tab control with multiple tabs. On one of my tabs (Program) I have 2 subforms, one for people assigned to program "A" and one for who is assigned to program "B". I need to hide the appropriate tab on both actions: When the "Program" tab is clicked AND when the listbox is clicked with a different person.

On the tab control I have tried this but it doesn't seem like it works:
Code:
Private Sub Program_Click()
If Me.Parent!Program.Value = OCS Then
Me.frmOCS.Visible = True
Me.frmDirect.Visible = False
End If

If Me.Parent!Program.Value = DIRECT Then
Me.frmDirect.Visible = True
Me.frmOCS.Visible = False
End If
End Sub

As far as the Sub ListBox_Click(), I'm not sure where to begin. Any input is appreciated!
 

essaytee

Need a good one-liner.
Local time
Tomorrow, 03:36
Joined
Oct 20, 2008
Messages
512
If I'm following along correctly, you want to know how to hide the tab pages of the tab control.

I created a test form, a command button (cmd_Test) and a tab control (tab_Test) with three pages.

In the click event of the command button, the following code toggles between hiding and unhiding page 2 (middle tab) of the tab control.

Code:
    If Me.tab_Test.Pages(1).Visible Then
        Me.tab_Test.Pages(1).Visible = False
    Else
        Me.tab_Test.Pages(1).Visible = True
    End If

Using your own test conditions you should be able to accomplish what you want.
 

essaytee

Need a good one-liner.
Local time
Tomorrow, 03:36
Joined
Oct 20, 2008
Messages
512
Following on from the above (my last post, if someone posts whilst I'm typing this).

In order to hide a page of the tab from clicking on a tab control, enter code in the click event of the Tab Control. What you would have to watch out for, and make allowances (error checking) for, is that if you click the same tab page control that you want to hide, this will not be allowed, an error will occur.

In relation to your Listbox, enter code in the AfterUpdate event to hide and unhide the Tab Pages or any other controls for that matter.
 
Last edited:

fresnel4

New member
Local time
Today, 12:36
Joined
Feb 17, 2019
Messages
3
I’m actually trying to hide a sub form on a tab. I could hide a tab but there’s multiple forms on a single tab, so I’m trying to only show the appropriate sub form on the tab based on the user’s program (specified in the list box). I hope that clears it up
 

essaytee

Need a good one-liner.
Local time
Tomorrow, 03:36
Joined
Oct 20, 2008
Messages
512
I’m actually trying to hide a sub form on a tab. I could hide a tab but there’s multiple forms on a single tab, so I’m trying to only show the appropriate sub form on the tab based on the user’s program (specified in the list box). I hope that clears it up

So in this instance, just reference the sub form directly and change it's visible property to either false or true.

In my test form, I added a subform (sub_FormTest) to a page of the tab control, it doesn't matter which page. From a command button enter the following code:

Code:
    If Me.sub_FormTest.Visible = True Then
        Me.sub_FormTest.Visible = False
    Else
        Me.sub_FormTest.Visible = True
    End If

This simply toggles between hiding and unhiding the subform. Using your own test conditions within the AfterUpdate event of your Listbox control you will be able to hide and unhide your subform.
 

fresnel4

New member
Local time
Today, 12:36
Joined
Feb 17, 2019
Messages
3
So in this instance, just reference the sub form directly and change it's visible property to either false or true.

In my test form, I added a subform (sub_FormTest) to a page of the tab control, it doesn't matter which page. From a command button enter the following code:

Code:
    If Me.sub_FormTest.Visible = True Then
        Me.sub_FormTest.Visible = False
    Else
        Me.sub_FormTest.Visible = True
    End If

This simply toggles between hiding and unhiding the subform. Using your own test conditions within the AfterUpdate event of your Listbox control you will be able to hide and unhide your subform.

I was absolutely overthinking. I actually had to use

Code:
Me.sub_FormTest.Form.Visible = False

But I was thinking I had to refer to the TAB CONTROL first which was giving me fits. Thank you for the help!
 

June7

AWF VIP
Local time
Today, 09:36
Joined
Mar 9, 2014
Messages
5,466
Refer to the subform container control. I always name container different from the object it holds, such as ctrDetails:

Me.ctrDetails.Visible = False
 

essaytee

Need a good one-liner.
Local time
Tomorrow, 03:36
Joined
Oct 20, 2008
Messages
512
I was absolutely overthinking. I actually had to use

Code:
Me.sub_FormTest.Form.Visible = False
But I was thinking I had to refer to the TAB CONTROL first which was giving me fits. Thank you for the help!
You're welcome.
 

Users who are viewing this thread

Top Bottom