562 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
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.
This blog is part of our Excel VBA tutorial. Wise Owl's main business is running Excel, VBA and other courses for businesses.
|
A multipage control allows you to get lots of information into a single form:
![]() |
![]() |
![]() |
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.
Make sure that you use the MultiPage (not the TabStrip) control!
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:
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.
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:
In this form:
Each page of a multipage control has its own tab order:
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.
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
Me.txtName.SetFocus
'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
Me.txtName.SetFocus
would crash the macro, because you can't go to a control which isn't on the active page of the MultiPage.
Parts of this blog |
---|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2023. All Rights Reserved.