problem with list box

  • Thread starter Thread starter Stuart Holley
  • Start date Start date
S

Stuart Holley

I am trying to place all selected items from a multiselect listbox in
to a text box but keep getting the following error when reaching the
end of the list.

Run time error '-2147024809 (80070057)

could not get selected property. invalid argument

my code is as follows


Private Sub CommandButton13_Click()

'Dim noinlistbox1 As Long
Dim i As Long

TextBox11.Value = ""

For i = 0 To ListBox1.ListCount
If ListBox1.Selected(i) = True Then
TextBox11.Text = TextBox11.Text + Chr$(13) +
ListBox1.List(i)
End If
Next i

End Sub


help would be most appreciated


Stuart
 
Stuart,

The list index starts at 0.
The list count start with 1.
Change: For i = 0 To ListBox1.ListCount
to: For i = 0 To (ListBox1.ListCount -1)

This is one circumstance that the Help file does cover...
Quote: "ListCount is always one greater than the largest value for the
ListIndex property"

Regards,
Jim Cone
San Francisco, CA
 
Jim

Many thanks


Stuart,

The list index starts at 0.
The list count start with 1.
Change: For i = 0 To ListBox1.ListCount
to: For i = 0 To (ListBox1.ListCount -1)

This is one circumstance that the Help file does cover...
Quote: "ListCount is always one greater than the largest value for the
ListIndex property"

Regards,
Jim Cone
San Francisco, CA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top