How do I test for which tab is active in VBA?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    How do I test for which tab is active in VBA?

    I have a Select All check box on one of my databases. It currently runs an update query that selects or unselects all of the records in a subform. I now have two subforms on separate tabs in a tab control. I would like to be able to have the Select All checkbox know which tab is visible and do the selecting/unselecting on just that form. I initially thought I would test for which tab had the focus, but I immediately realized that once I click on the Select All checkbox, no tab has focus. Is there a way to test which tab is active/visible?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Me.tabControlNa me returns the index of the tab that is active.

    Comment

    • Seth Schrock
      Recognized Expert Specialist
      • Dec 2010
      • 2965

      #3
      So I could do something like:

      Code:
      If Me.tabControlName = "Devices_tab" Then 'the name of one of my tabs
          'Do something
      Else
          'Do something else
      End If
      Last edited by Seth Schrock; Nov 15 '12, 05:25 PM. Reason: Added Double Quotes in line 1 of code

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Almost but not quite, it's the tab number starting at 0. If you want the name, you will have to use the tab number to get it from the pages collection and then get the name from that.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32661

          #5
          Originally posted by Rabbit
          Rabbit:
          Me.tabControlNa me returns the index of the tab that is active.
          Surely that returns a Page object Rabbit? I can't see how this can work. Am I missing something?

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            I'll admit the behavior is a bit odd. But if you MsgBox the control or Debug.Print it, it shows you a number, the number of the tab that is on top.

            Comment

            • Seth Schrock
              Recognized Expert Specialist
              • Dec 2010
              • 2965

              #7
              It works. I never would have guessed that, but I can't argue with the results. Thanks rabbit.

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32661

                #8
                Sorry. My bad. It's the TabControl you're printing rather than the Page itself. The TabControl has a default property called .Value which reflects which of its Pages is currently selected. Much like a Frame returns a value representing which of the Options within it is currently selected.

                Comment

                Working...