557 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
Advanced controls in userforms with VBA macros
Part five 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.
The previous two parts of this blog have considered general features for combo and list boxes, but there is one thing you can do with a listbox that you can't do with a combo box: allow a user to select lots of records at the same time.
This is the easy part! Just change the properties of the listbox as follows:
You can choose 3 possible values for a MultiSelect listbox. The difference between frmMultiSelectMulti and frmMultiSelectExtended (who thinks up these names?) is that with the latter you can click and drag to select lots of adjacent items at the same time.
You can then click on any item to select (or deselect) it:
Here we have selected at least 3 departments (more may be shown selected if we scroll down).
You can loop over the items in the Selected array to find out which items were chosen:
Private Sub btnOrder_Click()
Dim EachDepartment As Long
'loop over all of the items in the list
For EachDepartment = 1 To Me.lstDepartment.ListCount
'for each item, see if it was selected
If Me.lstDepartment.Selected(EachDepartment - 1) = True Then
'do something with it!
Debug.Print Me.lstDepartment.List(EachDepartment - 1)
Notice here that the ListCount property gives the number of items in the list (numbered from 1), but the Selected array is numbered from 0.
|Parts of this blog|
25 Aytoun Street