Advanced controls in userforms with VBA macros
Part two of a nine-part series of blogs

The two previous parts of this mini-blog have shown how to draw forms and how to write code to handle form events. This final part shows how to add some of the more exotic controls to user forms, like combo boxes, list boxes, multipage controls, spinners and option buttons.

  1. Advanced Controls - Our Example
  2. Multipage Controls (this blog)
  3. Combo boxes (and list boxes)
  4. Multiple Column Combo Boxes and Listboxes
  5. Multi-select ListBoxes
  6. SpinButtons (Spinners)
  7. Check Boxes
  8. Option Buttons (Radio Buttons)
  9. The Calendar Control

This blog is part of our Excel VBA tutorial.  Wise Owl's main business is running Excel, VBA and other courses for businesses.

Posted by Andy Brown on 28 February 2012

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Multipage Controls

A multipage control allows you to get lots of information into a single form:

Multipage - page 1 Multipage - page 2 Multipage - page 3
Page 1 Page 2 Page 3

A TabStrip control, by contrast, is useless - for a TabStrip every "page" of the form contains the same boxes, so they can only be used to display records from a table.

Creating a MultiPage Control

Make sure that you use the MultiPage (not the TabStrip) control!

MultiPage control selected

Click on the MultiPage tool, and click where you want it to go on your form.


You can then insert, move, rename and delete pages using the right mouse button:

Context menu for multipage control

Right-click on the page tabs at the top of the control to add new pages or rename or move existing ones in a fairly obvious way.


How MultiPage Controls Work

In a multipage control, if you paste or add a control onto a page, it belongs to that page; otherwise, it belongs to the form:

Multipage with two boxes showing controls

In this form:


Each page of a multipage control has its own tab order:

Tab order dialog box for one page

Here we're looking at the tab order for the About you page of the multipage control.  The other pages will have their own tab orders.


Setting Focus to a Control on a Multipage

The only slight complication with a multipage is going to a control on it.  You do this - surprisingly - by setting the Value property of the MultiPage:

'check user chosen a name

If Len(Me.txtName.Text) = 0 Then

'if not, go to first page ...

MultiPage1.Value = 0

'... and go to the offending text box


'display error message and abort

MsgBox "You must say who is ordering drink!"

Exit Sub

End If

In the code above, the line:

'if not, go to first page ...

MultiPage1.Value = 0

makes the first page of the multipage the current one (the pages are numbered from 0).  Without it, the line:

'... and go to the offending text box


would crash the macro, because you can't go to a control which isn't on the active page of the MultiPage.


This blog has 0 threads Add post