list box problems

  • Thread starter Thread starter krzysztof via AccessMonster.com
  • Start date Start date
K

krzysztof via AccessMonster.com

Good afternoon...

I am not seeing my error on this one...this should be easy.

i have a listbox in a form, and i want to clear it. but the total number of
items can change. so i tried this code:

Dim i As Integer
Dim counter As Integer
counter = Me.list_Changed.ListCount - 1

For i = 0 To counter
Me.list_Changed.RemoveItem (i)
i = i + 1
Next

at first i determine how many items there are, then set the loop to run
through that many items.

seems simple enough? i keep getting a error "no item number '8'"

in my example there are 10 items in the list. (0 to 9) for the indexes,
hence the listcount - 1 above.

what am i not seeing?

thanks in advance
 
Let me make sure I understand...

You have a listbox, and you want a way to remove all items from the listbox.

Is this listbox using a RowSource value (i.e., a query or a table)?

If so, in code, you could use something like:

Me!lstMyListBox.RowSource = ""

to re-fill the listbox with ... nothing!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
actually no, the list box is a value list, and the data comes from a dao.
recordset

this is so odd that it is not working
thanks

Jeff said:
Let me make sure I understand...

You have a listbox, and you want a way to remove all items from the listbox.

Is this listbox using a RowSource value (i.e., a query or a table)?

If so, in code, you could use something like:

Me!lstMyListBox.RowSource = ""

to re-fill the listbox with ... nothing!

Regards

Jeff Boyce
Microsoft Office/Access MVP
Good afternoon...
[quoted text clipped - 24 lines]
thanks in advance
 
Sorry, no experience clearing a value list listbox. Have you searched
on-line (e.g., Google)?

Regards

Jeff Boyce
Microsoft Office/Access MVP

krzysztof via AccessMonster.com said:
actually no, the list box is a value list, and the data comes from a dao.
recordset

this is so odd that it is not working
thanks

Jeff said:
Let me make sure I understand...

You have a listbox, and you want a way to remove all items from the
listbox.

Is this listbox using a RowSource value (i.e., a query or a table)?

If so, in code, you could use something like:

Me!lstMyListBox.RowSource = ""

to re-fill the listbox with ... nothing!

Regards

Jeff Boyce
Microsoft Office/Access MVP
Good afternoon...
[quoted text clipped - 24 lines]
thanks in advance
 
the list box is a value list

In that case Jeff's suggestion ought to work. A "Value List" is simply a
string in the RowSource property separated by semicolons, so setting it to a
zero length string ("") should definitely do the trick.
 
Back
Top