Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 23

Thread: Help in Tab in user form

  1. #1
    VBAX Regular
    Joined
    Feb 2007
    Posts
    68
    Location

    Talking Help in Tab in user form


    Hi
    I have a tab control on my user form. I want help that how to use it.
    I want that user click on ?tab1? then it shows a massage box called ?tab1 activated ?
    And adds a control called textbox 1,
    And when user clicks on tab2 then it shows a massage box called ?tab2 activated ?
    And adds a control called textbox 2,

    How to do it?

    I have a sample workbook attached here.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub TabStrip1_Change()
    Select Case Me.TabStrip1.Value
    Case 0: MsgBox "Tab #1 activated"
    Case 1: MsgBox "Tab #2 activated"
    End Select
    End Sub
    [/vba]

    As for thetextboxes, I don't subscribe to adding controls dynamically, I prefer to add them at design time and hide/show them as required.

  3. #3
    VBAX Regular
    Joined
    Feb 2007
    Posts
    68
    Location
    hi xld
    It worked ! Thanks.

  4. #4
    VBAX Regular
    Joined
    Feb 2007
    Posts
    68
    Location
    Hi,
    how to activate the tab once before the Currant tab ?
    for eample when user clicks on tab2 I want to activate tab1
    and when user click on tab3 I want activate tab2........

    Have you any idea?

  5. #5
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    Trying to mess with your users' heads?


    Just set the tabstrip value to whichever tab you want e.g
    Me.TabStrip1.Value =2
    Glen

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why? You could then only get to tab2 by clicking tab 3, and never get to tab 3. Seems daft to me.

  7. #7
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    Oh wait, infinite loop.
    Glen

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Shouldn't do if it is click invoked, and you control re-entry.

  9. #9
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    Does a Tabstrip have a click event?

    Not sure.

    Must do.
    Glen

  10. #10
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    Ah yes, you need send a parameter when it's called.
    Glen

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Yes it does, but you are clicking the tab itself (as it is a tabstrip), which is how you select atab, which is why I think the request is just plain daft, you click tab2 to go to tab2 and you go to tab1!
    Last edited by Bob Phillips; 02-20-2007 at 04:22 AM.

  12. #12
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    Well I guess we'll find out why he wants to do it but I'm with you on this; sounds like a bad idea.
    Glen

  13. #13
    VBAX Regular
    Joined
    Feb 2007
    Posts
    68
    Location
    Hi,
    I am trying to make a tabed browsing
    Control , so like you have in IE 7 , I have 2 tabs on that ,the first in tab1 the last one is as “ +” sign so when user clicks on it adds a tab between the tab1 and “+” , I have the following code , but the problem is that the code doesn’t activate the last added tab , so what to for it ?

    something is wrong , so help me !


    [vba]Private Sub TabStrip1_Change()

    Dim a As Integer
    a = Me.TabStrip1.Tabs.Count
    If TabStrip1.Value = a-1 Then
    TabStrip1.Tabs.Add "", "page 2", a - 1
    End If
    End Sub[/vba]

  14. #14
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You mean tabbed browsing as in Firefox, as it has been for a long time in FF.

    [vba]

    Private Sub TabStrip1_Change()
    Dim cTabs As Integer
    With Me.TabStrip1
    cTabs = .Tabs.Count
    If .Tabs(cTabs - 1).Caption = "+" Then
    .Tabs.Add "", "page " & cTabs, cTabs - 1
    End If
    End With
    End Sub
    [/vba]

  15. #15
    VBAX Regular
    Joined
    Feb 2007
    Posts
    68
    Location
    You mean tabbed browsing as in Firefox, as it has been for a long time in FF.
    Exactly

    But in your example, it inserts tabs both time , when I click on tab 1 and when I click on “+” , I just want to add a tab BETWEEN these two tabs only when user clicks on “+” and then to activate the ADDED Tab .

    What’s the way?

    Regards,
    Dan

  16. #16
    VBAX Regular
    Joined
    Feb 2007
    Posts
    68
    Location
    this works fine :
    [VBA]Private Sub TabStrip2_Change()
    Dim cTabs As Integer
    With Me.TabStrip2
    cTabs = .Tabs.Count
    If TabStrip2.Value = cTabs - 1 Then
    .Tabs.Add "", "page " & cTabs, cTabs - 1
    End If
    End With

    End Sub
    [/VBA]

    but what to do to activate the added tab ?

  17. #17
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub TabStrip1_Click(ByVal Index As Long)
    Dim cTabs As Integer
    With Me.TabStrip1
    cTabs = .Tabs.Count
    If .Index = cTabs - 1 Then
    .Tabs.Add "", "page " & cTabs, cTabs - 1
    .Value = cTabs - 1
    End If
    End With

    End Sub
    [/vba]

  18. #18
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    I think you need

    [VBA]If .SelectedItem.Index = cTabs - 1 Then [/VBA]
    Glen

  19. #19
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    Or drop the "." in front of Index
    Glen

  20. #20
    VBAX Regular
    Joined
    Feb 2007
    Posts
    68
    Location
    Hi every one,
    That code works fine in all the ways. Now I want to stop user if the count of total tabs (cTabs) are greater than 20 (I mean no to let the user to open more than 12 tabs)

    Thanks,
    Dan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •