Combo Box Control, List Box Control.
You can use the Column property to refer to a specific column, or column and row combination, in a multiple-column combo box or list box. Use 0 to refer to the first column, 1 to refer to the second column, and so on. Use 0 to refer to the first row, 1 to refer to the second row, and so on. For example, in a list box containing a column of customer IDs and a column of customer names, you could refer to the customer name in the second column and fifth row as:
Forms![Contacts]![Customers].Column(1, 4)
The Column property uses the following settings.
Setting | Description |
controlname | A string expression identifying the name of the combo box or list box control. |
column | An Integer value that can range from 0 to the value of the ColumnCount property minus one. |
row | Optional. An Integer value that can range from 0 to the value of the ListCount property minus one. |
This property setting is only available in a macro or Visual Basic.
You can use the Column property to assign the contents of a combo box or list box to another control, such as a text box. For example, to set the ControlSource property of a text box to the value in the second column of a list box, you could use the following expression:
= Forms![Customers]![CompanyName].Column(1)
If the user has made no selection when you refer to a column in a combo box or list box, the Column property setting will be Null. You can use the IsNull function to determine if a selection has been made as in the following example.
If IsNull(Forms![Customers]![Country]) Then MsgBox "No selection."
Note To determine how many columns a combo box or list box has, you can inspect the ColumnCount property setting.
The Column property returns a Variant of VarType 8 (String).
BoundColumn Property, ColumnCount Property, ColumnHeads Property, ColumnWidths Property, ListCount Property, MultiSelect Property, Nz Function, Selected Property.
The following example uses the Column property and the ColumnCount property to print the values of a list box selection. Notice that if there is no selection, the value of lstCustomerNames will be Null.
Sub Read_ListBox() Dim intNumColumns As Integer, i As Integer Dim frmCust As Form Set frmCust = Forms![frmCustomers] If Not IsNull(frmCust![lstCustomerNames]) Then ' Any selection? intNumColumns = frmCust![lstCustomerNames].ColumnCount Debug.Print "The list box contains "; intNumColumns; _ IIf(intNumColumns = 1, " column", " columns"); " of data." Debug.Print "The current selection contains:" For i = 0 To intNumColumns - 1 ' Print column data. Debug.Print frmCust![lstCustomerNames].Column(i) Next i Else Debug.Print "You haven't selected an entry in the list box." End IfSub