Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Additems from one listbox with multiple columns to another
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. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Additems from one listbox with multiple columns to another
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 .... BigPig wrote: 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. -- Dave Peterson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Additems from one listbox with multiple columns to another
Hi David,
"Dave Peterson" wrote: 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. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Additems from one listbox with multiple columns to another
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 BigPig wrote: Hi David, "Dave Peterson" wrote: 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. -- Dave Peterson |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Additems from one listbox with multiple columns to another
Thank you Dave.
"Dave Peterson" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
deleting corresponding columns on a multiple select listbox | Excel Programming | |||
adding multiple columns to a listbox | Excel Programming | |||
multiple columns / rows to be referenced through a listbox | Excel Discussion (Misc queries) | |||
Selecting multiple items and columns from ListBox | Excel Programming | |||
Multi-column ListBox. Multiple bound columns??? | Excel Programming |