Userform - Is there any situation when it worths using Tabstrip instead of Pages?

Jamualson

Board Regular
Joined
Feb 17, 2021
Messages
145
Office Version
  1. 2019
Platform
  1. Windows
Seems to me that working with pages is much effective and it there is a much lower chance to make errors.

Tabstrip has only 1 advantage: you can recreate layouts really fast. But if you can bulk select all control and just throw on a new page, then this advantage seems not so attractive.

So what is the advantage so tabs are worth using? I see no advantage in practice. Thank you very much, have a nice day
 
There are no controls on a TabStrip. Ever, under any circumstances, You never have any controls on any tab of a tab strip.
There are never any option buttons on any TabStrip, so there aren't any values to save.
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
There are no controls on a TabStrip. Ever, under any circumstances, You never have any controls on any tab of a tab strip.
There are never any option buttons on any TabStrip, so there aren't any values to save.
Thx. U use a tabstrip because u want 2 tabs and same control. For example you put an option button.
Then how do you save out option button value when u change tab and option button will have another caption etc on another tab? U have to save the contents of controls on a tab before switch. Not?
 
Upvote 0
You don't use a tabstip for that purpose.
But as an exersize, I came up with this scheme that is for 3 tabs and 4 option buttons.

VBA Code:
' in userform's code module

Dim PreviousTabStripValue As Long

Private Sub TabStrip1_Change()
    Rem save option button values for last tab
    With TabStrip1.Tabs(PreviousTabStripValue)
        .Tag = OptionButton1.Value
        .Tag = .Tag & "," & OptionButton2.Value
        .Tag = .Tag & "," & OptionButton3.Value
        .Tag = .Tag & "," & OptionButton4.Value
        Me.Caption = .Tag
    End With

    Rem change option button captions
    OptionButton1.Caption = Split(OptionButton1.Tag, ",")(TabStrip1.Value)
    OptionButton2.Caption = Split(OptionButton2.Tag, ",")(TabStrip1.Value)
    OptionButton3.Caption = Split(OptionButton3.Tag, ",")(TabStrip1.Value)
    OptionButton4.Caption = Split(OptionButton4.Tag, ",")(TabStrip1.Value)
  
    Rem restore option button values for new tab
    With TabStrip1.SelectedItem
        OptionButton1.Value = (Split(.Tag & ",,,,", ",")(0) = "True")
        OptionButton2.Value = (Split(.Tag & ",,,,", ",")(1) = "True")
        OptionButton3.Value = (Split(.Tag & ",,,,", ",")(2) = "True")
        OptionButton4.Value = (Split(.Tag & ",,,,", ",")(3) = "True")
    End With
  
    PreviousTabStripValue = TabStrip1.Value
End Sub

Private Sub UserForm_Initialize()
    Dim i As Long
  
    Do Until TabStrip1.Tabs.Count >= 3
        TabStrip1.Tabs.Add
    Loop
  
    Rem static captions for tabstrip tabs
    With TabStrip1
        .Tabs(0).Caption = "A options"
        .Tabs(1).Caption = "B options"
        .Tabs(2).Caption = "C options"
    End With
  
    Rem captions for option buttons to change as tabstrip is changed
    OptionButton1.Tag = "option A-1,option B-1,option C-1"
    OptionButton2.Tag = "option A-2,option B-2,option C-2"
    OptionButton3.Tag = "option A-3,option B-3,option C-3"
    OptionButton4.Tag = "option A-4,option B-4,option C-4"
  
    Rem itnitalize
    For i = 0 To TabStrip1.Tabs.Count - 1
        TabStrip1.Value = i
    Next i
    TabStrip1.Value = 0
  
End Sub

The values are preserved in the .Tag property of each of the tabstrip's tabs.
I might say something about generalizing to a Class module, but nothing overides the Don't Do It, a MultiPage is the type of control you want for this.
 
Upvote 0
Solution
You don't use a tabstip for that purpose.
But as an exersize, I came up with this scheme that is for 3 tabs and 4 option buttons.

VBA Code:
' in userform's code module

Dim PreviousTabStripValue As Long

Private Sub TabStrip1_Change()
    Rem save option button values for last tab
    With TabStrip1.Tabs(PreviousTabStripValue)
        .Tag = OptionButton1.Value
        .Tag = .Tag & "," & OptionButton2.Value
        .Tag = .Tag & "," & OptionButton3.Value
        .Tag = .Tag & "," & OptionButton4.Value
        Me.Caption = .Tag
    End With

    Rem change option button captions
    OptionButton1.Caption = Split(OptionButton1.Tag, ",")(TabStrip1.Value)
    OptionButton2.Caption = Split(OptionButton2.Tag, ",")(TabStrip1.Value)
    OptionButton3.Caption = Split(OptionButton3.Tag, ",")(TabStrip1.Value)
    OptionButton4.Caption = Split(OptionButton4.Tag, ",")(TabStrip1.Value)
 
    Rem restore option button values for new tab
    With TabStrip1.SelectedItem
        OptionButton1.Value = (Split(.Tag & ",,,,", ",")(0) = "True")
        OptionButton2.Value = (Split(.Tag & ",,,,", ",")(1) = "True")
        OptionButton3.Value = (Split(.Tag & ",,,,", ",")(2) = "True")
        OptionButton4.Value = (Split(.Tag & ",,,,", ",")(3) = "True")
    End With
 
    PreviousTabStripValue = TabStrip1.Value
End Sub

Private Sub UserForm_Initialize()
    Dim i As Long
 
    Do Until TabStrip1.Tabs.Count >= 3
        TabStrip1.Tabs.Add
    Loop
 
    Rem static captions for tabstrip tabs
    With TabStrip1
        .Tabs(0).Caption = "A options"
        .Tabs(1).Caption = "B options"
        .Tabs(2).Caption = "C options"
    End With
 
    Rem captions for option buttons to change as tabstrip is changed
    OptionButton1.Tag = "option A-1,option B-1,option C-1"
    OptionButton2.Tag = "option A-2,option B-2,option C-2"
    OptionButton3.Tag = "option A-3,option B-3,option C-3"
    OptionButton4.Tag = "option A-4,option B-4,option C-4"
 
    Rem itnitalize
    For i = 0 To TabStrip1.Tabs.Count - 1
        TabStrip1.Value = i
    Next i
    TabStrip1.Value = 0
 
End Sub

The values are preserved in the .Tag property of each of the tabstrip's tabs.
I might say something about generalizing to a Class module, but nothing overides the Don't Do It, a MultiPage is the type of control you want for this.
Thank you very much, this is the piece of information I needed. Great example. thank you.
 
Upvote 0

Forum statistics

Threads
1,215,261
Messages
6,123,931
Members
449,134
Latest member
NickWBA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top