Column, ColumnCount Properties Example

The following example uses the Column property and the ColumnCount property to print the values of a list box selection.

Sub Read_ListBox()
    Dim intNumColumns As Integer, inti As Integer
    Dim frmCust As Form

    Set frmCust = Forms!frmCustomers
    If frmCust!lstCustomerNames.ItemsSelected.Count > 0 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 inti = 0 To intNumColumns - 1
            ' Print column data.
            Debug.Print frmCust!lstCustomerNames.Column(inti)
        Next inti
    Else
        Debug.Print "You haven't selected an entry in the " _
            & "list box."
    End If
End Sub