Hide and display subforms in tab conrol with checkbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neelsfer
    Contributor
    • Oct 2010
    • 547

    Hide and display subforms in tab conrol with checkbox

    I have 2 different subforms in a tab control (TabCtl124).
    When i open main form (RacesetupF), i would like 2 of the tab control and their subforms to be hidden except tabcontrol 1 and its subform as default.
    I have a checkbox control called TimeCBox with the 3 different options.
    The following code hide the Tab control on startup
    Code:
    Me.TabCtl124.Visible = false
    then i will need code to call up
    Code:
     Private Sub TimeCBox_Click()
    On Error GoTo TimeCBox_Click_Err
    If Forms![RaceSetupF]![TimeCBox] = 1 Then Me.TabCtl124.Pages(1).Visible = True
    If Forms![RaceSetupF]![TimeCBox] = 2 Then Me.TabCtl124.Pages(2).Visible = True
    If Forms![RaceSetupF]![TimeCBox] = 3 Then Me.TabCtl124.Pages(3).Visible = True
    TimeCBox_Click_Exit:
        Exit Sub
    TimeCBox_Click_Err:
        MsgBox Error$
        Resume TimeCBox_Click_Exit
    End Sub
    AS you open one subform in checkbox, the others must be invisible

    Please help it is not working.
  • neelsfer
    Contributor
    • Oct 2010
    • 547

    #2
    I have changed the coding now for 2 tabs to be visible and disappear with the checkbox
    I don't hide the tabs on load. it works now!
    Code:
    Private Sub TimeCBox_Click()
    On Error GoTo TimeCBox_Click_Err
    If Forms![RaceSetupF]![TimeCBox] = 1 Then
    Me.TabCtl124.Pages(0).Visible = True
    Me.TabCtl124.Pages(1).Visible = False
    End If
    If Forms![RaceSetupF]![TimeCBox] = 2 Then
    Me.TabCtl124.Pages(1).Visible = True
    Me.TabCtl124.Pages(0).Visible = False
    End If
    TimeCBox_Click_Exit:
        Exit Sub
    
    TimeCBox_Click_Err:
        MsgBox Error$
        Resume TimeCBox_Click_Exit
    End Sub

    Comment

    • neelsfer
      Contributor
      • Oct 2010
      • 547

      #3
      How can i make the following 2 tabs hidden on load of form
      Code:
      # Me.TabCtl124.Pages(0).Visible = False
      # Me.TabCtl124.Pages(1).Visible = False
      i get a warning that you cant hide a control that has a focus

      Comment

      • mshmyob
        Recognized Expert Contributor
        • Jan 2008
        • 903

        #4
        Just reverse the order.

        This assumes a triState checkbox.

        Code for Onclick event of Checkbox
        Code:
          If IsNull(TimeCBox) Then
            Forms!RaceSetupF.TabCtl124.Pages(0).Visible = False
            Forms!RaceSetupF.TabCtl124.Pages(1).Visible = False
            Forms!RaceSetupF.TabCtl124.Pages(2).Visible = True
          Else
            Select Case TimeCBox
            
             Case Is = -1 ' checked
                Forms!RaceSetupF.TabCtl124.Pages(0).Visible = True
                Forms!RaceSetupF.TabCtl124.Pages(1).Visible = False
                Forms!RaceSetupF.TabCtl124.Pages(2).Visible = False
             Case Is = 0 ' unchecked
                Forms!RaceSetupF.TabCtl124.Pages(0).Visible = False
                Forms!RaceSetupF.TabCtl124.Pages(1).Visible = True
                Forms!RaceSetupF.TabCtl124.Pages(2).Visible = False
            Case Else
             MsgBox ("Please make a selection")
             
            End Select
        End If
        Code for Onload event

        Code:
        Forms!RaceSetupF.TabCtl124.Pages(2).Visible = False
        Forms!RaceSetupF.TabCtl124.Pages(1).Visible = False
        Forms!RaceSetupF.TabCtl124.Pages(0).Visible = True
        cheers,

        Comment

        Working...