none
Tab control - how do I make a tab be the active tab ? RRS feed

  • Question

  • I have a tab control with 2 tabs. My table contains 2 types of records. For one type of record both tabs are applicable and for the other type of record only tab 2 is applicable.

    In the form current event, I manipulate the .visible property to show the correct tabs. Ok so far.

    HOWEVER, after displaying a type 2 record (where I set tab1 visible = false), when I access a type 1 record and set tab1 visible = true, tab 2 is still at the front. In this case, I need tab1 to be at the front. How do I do this. NOTE: I do not want this tab to have the focus or any controls on the tab to have the focus. I just need tab 1 to be in the front and tab 2 to be in the back.

    I looked in Help and could find nothing about this (as usual).

    Wednesday, April 11, 2012 1:51 AM

Answers

  • You can read and set the value of a tab control. The tab control has the value equal to the active tab.

    To find out which tab is the active tab, you can do:
    Debug.Print Me.[TabControlName]

    Tab control tabs are numbered starting at 0.
    To make the first tab the active tab, use:
    Me.[TabControlName] = 0

    The above code makes the first tab the active tab.

    To make the second tab the active tab:
    Me.[TabControlName] = 1

    If you don't want the active tab to have the focus, then you must move the focus to something else after you have finished setting which tab is the active one.

    The other event we use to manipulate a tab control is the Change event for tab controls.

    On the change event of the tab control, you can go:

    If Me.[TabControlName] = 0 Then
    'code to do something here
    Else
    'code to do a different thing here
    End If

    Note: replace my object names with your own.


    Jeanette Cunningham

    Wednesday, April 11, 2012 3:00 AM

All replies

  • Use the following code to set Tab1 in front:

    ' Note: Page 0 is Tab 1
    Me.YourTabControlName.Pages(0).SetFocus
    

    Hope this helps,

    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.

    Wednesday, April 11, 2012 2:58 AM
  • You can read and set the value of a tab control. The tab control has the value equal to the active tab.

    To find out which tab is the active tab, you can do:
    Debug.Print Me.[TabControlName]

    Tab control tabs are numbered starting at 0.
    To make the first tab the active tab, use:
    Me.[TabControlName] = 0

    The above code makes the first tab the active tab.

    To make the second tab the active tab:
    Me.[TabControlName] = 1

    If you don't want the active tab to have the focus, then you must move the focus to something else after you have finished setting which tab is the active one.

    The other event we use to manipulate a tab control is the Change event for tab controls.

    On the change event of the tab control, you can go:

    If Me.[TabControlName] = 0 Then
    'code to do something here
    Else
    'code to do a different thing here
    End If

    Note: replace my object names with your own.


    Jeanette Cunningham

    Wednesday, April 11, 2012 3:00 AM