Tab Control - Referring to a page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • doma23
    New Member
    • May 2010
    • 107

    Tab Control - Referring to a page

    Hi,
    The problem is next: I have a tab control with 5 pages.
    On each tab page I have group of controls for 5 different periods. I tagged groups as "Period1", "Period2", "Period3" and so on.
    On the bottom, after each Period, I have a delete button.
    When that button is clicked I want to clear all controls for that specific period, and only on that specific page of tab control.

    I have the following code for the OnClick event of delete button:
    Code:
    For Each ctl In Form_frmMain.Controls
        If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
            If ctl.Tag = "Period1" And Form_frmMain.TabCtl189.Value="1" Then
            ctl.Value = Null
            End If
        End If
    Next ctl
    The problem is that the this clears all the data on the other tab pages as well (where the control tag is "Period1"). How can I make it to clear only the controls wher TabCtl189.Value =1 (the second page).

    Tnx!
  • doma23
    New Member
    • May 2010
    • 107

    #2
    I've been trying to do this for the last one hour, and just when I've posted the question, I've found the solution:
    This is the correct code:
    Code:
    For Each ctl In Form_frmMain.Pagina91.controls
        If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
            If ctl.Tag = "Period1" Then
            ctl.Value = Null
            End If
        End If
    Next ctl
    Funny...

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32653

      #3
      So, Pagina91 is the name of one of the pages on the Tab control TabCtl189?

      Essentially, Pages on Tab controls have a collection of Controls just as Forms do (with some overlap of course). Another identifier is that all such controls have the page as their .Parent property.

      Comment

      • doma23
        New Member
        • May 2010
        • 107

        #4
        Yeah, Pagina91 is one of the pages on tab control TabCtl189.
        I didn't know about .Parent property. Nice, it's good to know.
        Basically, I coul've done it also by using this:
        Code:
        If ctl.Tag = "Period1" and ctl.Parent = "Pagina91" Then
        ?

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32653

          #5
          Almost :)

          Either :
          Code:
          If ctl.Tag = "Period1" and ctl.Parent.Name = "Pagina91" Then
          or :
          Code:
          If ctl.Tag = "Period1" and ctl.Parent Is Me.Pagina91 Then
          Comparing objects is done with the keyword Is.

          Comment

          Working...