Additems from one listbox with multiple columns to another

B

BigPig

Hello All,

I am trying to add selected items from one listbox to another on the same
form. I get this error when running the code below: Run-time error '381':
Could not set the list property. Invalid property array index.

Here's the code: Where the form is frm_billing_screen, the listbox that I
want to retrieve data from is lst_bs_school and the listbox that I want to
additems to is lst_bs_bm. lst_bs_school has a rowsource, but the other does
not. I'm hoping you're not going to tell me that I can't use the rowsource
property for the one listbox.

With frm_billing_screen
Dim x As Integer
For x = 0 To .lst_bs_school.ListCount - 1

..lst_bs_bm.Clear
..lst_bs_bm.ColumnCount = 6
..lst_bs_bm.ColumnWidths = "49.95 pt;75 pt;60 pt;49.95 pt;40 pt;100 pt"

If .lst_bs_school.Selected(x) = True Then
..lst_bs_bm.AddItem .lst_bs_school.List(x, 0)
..lst_bs_bm.List(x, 2) = .lst_bs_school.List(x, 1)
..lst_bs_bm.List(x, 3) = .lst_bs_school.List(x, 2)
..lst_bs_bm.List(x, 4) = .lst_bs_school.List(x, 3)
..lst_bs_bm.List(x, 5) = .lst_bs_school.List(x, 4)
..lst_bs_bm.List(x, 6) = .lst_bs_school.List(x, 5)
..lst_bs_school.Selected(x) = False
End If
Next
End With

Thanks.
 
D

Dave Peterson

Maybe you assigned a .list in code or while you were designing the form.

I'd add one more line:

....
..lst_bs_bm.Clear
..lst_bs_bm.list = "" '<-- Added
....
 
B

BigPig

Hi David,


Dave Peterson said:
Maybe you assigned a .list in code or while you were designing the form.

I'd add one more line:

....
..lst_bs_bm.Clear
..lst_bs_bm.list = "" '<-- Added
....

I tried as you suggested. Checked over the rest of my code and the listbox
properties, but didn't see anything.
I received the same error as before but with: ..lst_bs_bm.list="". Took it
out and tried again, but still the same error on the same line:
..lst_bs_bm.List(x, 2) = .lst_bs_school.List(x, 1)

If I take out all the entries other than additem (.list..), it adds as it
should but only in the 1st column (out of 6).

Thank you, your advice is always appreciated.
 
D

Dave Peterson

What line causes the error?

I didn't notice this before, but I think you'll want to change this portion:

If .lst_bs_school.Selected(x) = True Then
.lst_bs_bm.AddItem .lst_bs_school.List(x, 0)
.lst_bs_bm.List(.lst_bs_bm.listcount-1, 2) = .lst_bs_school.List(x, 1)
.lst_bs_bm.List(.lst_bs_bm.listcount-1, 3) = .lst_bs_school.List(x, 2)
.lst_bs_bm.List(.lst_bs_bm.listcount-1, 4) = .lst_bs_school.List(x, 3)
.lst_bs_bm.List(.lst_bs_bm.listcount-1, 5) = .lst_bs_school.List(x, 4)
.lst_bs_bm.List(.lst_bs_bm.listcount-1, 6) = .lst_bs_school.List(x, 5)
'.lst_bs_school.Selected(x) = False
End If
 

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

Top