1

I have a UserForm with a ListBox with 3 columns, the first column is filled on Initialization by an array. The 2nd and 3rd column are left empty. On selection, an inputbox is called via a function, to input and verify a number which I need in the second column. I've tried this with the List property but I get the error

Run-Time error '380':

Could not set the List property. Invalid property value.

Here is the sub which manipulates the Listbox:

Private Sub lstKarren_Change()
    Dim i As Long
    Dim karName As String
    With Me.lstKarren
        For i = 0 To .ListCount - 1
            If .Selected(i) And Not Karren(i) Then
                Karren(i) = True
                .List(i, 1) = numValInput
            ElseIf Not .Selected(i) And Karren(i) Then
                Karren(i) = False
                .List(i, 1) = Empty
            End If
        Next i
    End With

End Sub

The debugger highlights the line:

.list(i, 1) = numValInput 'numValInput is function which returns a number as a string.

The code runs fine the moment I change it to .List(i) but then it changes the first column, not the second column. The information I found says the List property should do the trick to set the 2nd column but I fail to understand why I get the run-time error.

Community
  • 1
  • 1
SilentRevolution
  • 1,495
  • 1
  • 16
  • 31

1 Answers1

1

The problem was caused by the way the Listbox was polpulated, changing:

Me.lstKarren.List = Array("Selectie", "Links AB", "Links CD", "Rechts AB", "Rechts CD")

to:

With Me.lstKarren
    .AddItem "Selectie"
    .AddItem "Links AB"
    .AddItem "Links CD"
    .AddItem "Rechts AB"
    .AddItem "Rechts CD"
End With

Solved the problem.

SilentRevolution
  • 1,495
  • 1
  • 16
  • 31