Multi-select list box

Description

A multi-select list box displays up to 32 items in a list, from which the user can choose multiple items.

Events

The BeforeUserChanged and AfterUserChanged events run each time the user selects an item in the multi-select list box, or presses the up arrow or down arrow keys to move to a different list item. All other VBA field events function normally for a focusable multi-select list box field.

VBA usage

VBA uses a 32-bit numeric value when referencing the items selected in a multi-select list box. The numeric value takes into account both the number of items selected and their position in the list. The following table shows the position of an item in a multi-select list box, the item’s corresponding numeric value, and the calculation that derives the value:

[spacer]

List item

Numeric value

Calculated as...

1

1

2^0

2

2

2^1

3

4

2^2

4

8

2^3

31

1,073,741,824

2^30


The value of the list is the sum of the selected items’ numeric values. If you select items 1, 3 and 4, the value of the multi-select list box is 13 (total = 1 + 4 + 8). An easier way to determine the value of the list is to select multiple items, then view the field’s Value property in the Visual Basic Properties window.

Examples

To select a single item in a multi-select list box, set the multi-select list box’s value to the item’s numeric value (noted in the previous table). The following example selects list item 4 by setting the list box’s value to 8:

Private Sub Window_BeforeOpen(OpenVisible As Boolean)
	'Select Payroll in the list
	IncludeinLookup = 8
End Sub

To select multiple items in a multi-select list box, add the list items numeric values together. The following example selects list items 1, 3 and 4 by setting the field to the sum of the items’ integer values (1 + 4 + 8 = 13):

Private Sub Window_BeforeOpen(OpenVisible As Boolean)
	'Select Sales, Purchasing and Payroll
	IncludeinLookup = 13
End Sub


Documentation Feedback