3

Community, I am currently hiding my tabs on my userform multipage except for the current tab. The user can click buttons to switch back and forth between pages. Some buttons share sub routines. When a user clicks a button, it hides the previous tab once the new tab has been selected. I suppose this is a dual question.

1) How can I get the previous tab selection value?

2) How can I loop through my tab values? My objective is to test the current tab caption or value against all the others. Figured this would be an easy way of hiding them all regardless as to which page and which button calls the subroutine.

Right now I only have this for one tab button...

Sub NewCreditSetup()
    MultiPage1.Pages(1).Visible = True
    MultiPage1.Value = 1
    MultiPage1.Pages(0).Visible = False
    //More code displaying tab...irrelevant
End Sub  
Kazimierz Jawor
  • 18,861
  • 7
  • 35
  • 55
CBC_NS
  • 1,961
  • 4
  • 27
  • 47
  • what do you mean by 'buttons'? could you attach a screen shot presenting your 'buttons'? Have you tried with 'pages' events, to catch them and trigger action as a result...? – Kazimierz Jawor Oct 24 '13 at 19:19

2 Answers2

5

You can use the tab change event to determine when the tab is changed and store the current tab index as a variable. Then when the tab is changed again, the tab in this variable becomes the previous tab.

Ie:

Private iPrevTab As Integer
Private iCurTab As Integer

Private Sub MultiPage1_Change()
    iPrevTab = iCurTab
    iCurTab = MultiPage1.Index

    'You can also check here what that tab is to do something with it
    If MultiPage1.Value = MultiPage1.Pages("mySpecialPage").Index Then
        'Go Nuts
    End If

End Sub

You can then loop through all the tabs and check against their name, caption or index. Eg:

Private Sub LoopTabs()
    Dim ii as Integer        

    for ii = 1 to MultiPage1.Pages.Count
        If MultiPage1.Pages(ii).Index = iPrevTab Then
           Debug.Print MultiPage1.Pages(ii).Name & " " & MultiPage1.Pages(ii).Caption
        End If
    Next ii
End Sub

It's probably also worth noting to be careful showing and hiding tabs as it is not common and could possibly confuse the user. I'll leave that up to you though.

CuberChase
  • 4,458
  • 5
  • 33
  • 52
  • This worked out beautifully. Thank you for the in site. I went with using your logic. During this process I also tried this which kind of worked. For each button that changes to a page, I was using the same routine to display content. I checked to see if the value of the current page was the page# given to the objective target page. If it wasn't, I assigned it to value x. I then made the current page invisible. (All tabs are invisible but the home page). Then, I made the objective target page visible. Thanks again. – CBC_NS Oct 25 '13 at 12:21
  • Great work. You can also use this to remember the state of the form. Ie if the user is on the second tab and closes it, the next time it loads you can set it to that tab. – CuberChase Oct 26 '13 at 02:59
1

I think that will help you.

Dim m As String
    m = MultiPage1.SelectedItem.Caption
MsgBox m
SandPiper
  • 2,816
  • 5
  • 30
  • 52
Rtronic
  • 635
  • 5
  • 6