简体   繁体   中英

Move to next Userform when MultiPage at last tab

I have code that directs a user to the next tab in a multiPage Userform. I need to add to the functionality that when the last tab has been reached, clicking the button will take the user to the next Userform instead.

Private Sub CommandButton3_Click()
Dim iNextPage As Long
With Me.MultiPage1
    iNextPage = .Value + 1
    If iNextPage < .Pages.Count Then
        .Pages(iNextPage).Visible = True
        .Value = iNextPage
    End If
End With
End Sub

Any help gratefully received

Multipages controls use the property Value to see the index of actual page. First page is 0, second one is 1 and so on

so if I type:

Debug.Print Me.MultiPage1.Value

I will get the active page from my multipage1 control.

also, you can set what page you want to see with value property. In Example, if you type:

Me.MultiPage1.Value=2

It will select page(2) of multipagecontrol (that means the third page, because first one is 0)

Also, there is another property. If you type:

Me.MultiPage1.Pages.Count

You will get total pages of multipage control. Total pages is ALWAYS 1 more than the index of last page. Example: If you have a total of 3 pages, that means that the index (property value) of your last page is 2.

So your code should be something like this:

Private Sub CommandButton3_click()


If Me.MultiPage1.Value = MyForm.MultiPage1.Pages.Count - 1 Then
    'I'm on the last tab. Code to go to next userform
Else
    Me.MultiPage1.Value = Me.MultiPage1.Value + 1
End If

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM