Userforms: MultiPage Controls

A common use for the MultiPage control is to create a custom wizard. Wizards generally have several screens where the user selects options or enters information. Most wizards also have a Next and a Back button with which the user navigates through the wizard.

This userform has a MultiPage control, two CommandButtons, and some labels that identify the page that’s showing. Notice in the properties window that the Style of the MultiPage is set to fmTabStyleNone. With this setting, the user won’t know which page he’s on with out some indication, like a label that says “Step 1 of 4.” By hiding the tabs, the user can’t skip around which is usually desirable.

multipage1

The Back and Next buttons are outside the MultiPage so we don’t need buttons for every page. The Value property of the MultiPage determines which page is showing. A Value of 0 denotes the first page and Pages.Count – 1 denotes the last. The code for the CommandButtons follows. The Tag properties are set so that a DisableControls sub can be used to prevent the user from going back from the first page or Next from the last page.

Private Sub cmdBack_Click()

Me.MultiPage1.Value = Me.MultiPage1.Value - 1
If Me.MultiPage1.Value = 0 Then
DisableControls Me, "Back"
Else
DisableControls Me, , , True
End If

End Sub Private Sub cmdNext_Click()

Me.MultiPage1.Value = Me.MultiPage1.Value + 1
If Me.MultiPage1.Value = Me.MultiPage1.Pages.Count - 1 Then
DisableControls Me, "Next"
Else
DisableControls Me, , , True
End If

End Sub

These buttons don’t do anything but change the Value property. Normally, you would code some validation routines in there to make sure that the user completed all the fields, although sometimes it’s better to do that at the end.

To finish it off, you’ll need some way for the user to get out of the wizard. I usually put a CommandButton on the last page that validates the data and does whatever function the userform is supposed to do.

When you’re designing your userform with a MultiPage control, don’t change the Style property until the end. Having the tabs visible while you’re moving controls around is quite handy.

3 thoughts on “Userforms: MultiPage Controls

  1. Hiding tabs by seting style property is interesting. Thanks for his info.
    -PM

  2. I have created an ActiveX Multipage control in the worksheet.
    I have also managed to add an button and textbox control to it.
    However, i can write any code to the button control to trigger some nos in the textbox.value.

    Please advise


Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.