How do you clear a listbox?

  • Thread starter Thread starter Deleted member 73419
  • Start date Start date
D

Deleted member 73419

Guest
Hi,

I've a listbox on a form which is populated with the RecordSet of a DAO query.

I want to clear the contents of the listbox but have been unsuccessful with the following.

Code:
listbox.clear
'Method or data member not found'.

Less:
listbox.RowSource = ""
or
listbox.RowSource = vbNullString
Does nothing, all the records are still in the listbox.

Code:
For i = 0 To listbox.ListCount - 1
  listbox.RemoveItem 0
Next
'The RowSourceType property must be set to Value List to use this method'

Does anyone have any other ideas?

Thanks
 
What exactly do you mean by "clearing" the listbox? Are you saying you want a blank listbox or just unselect all the items?
 
What exactly do you mean by "clearing" the listbox? Are you saying you want a blank listbox or just unselect all the items?
I'd like to clear the listbox.
 
The RowSource is required but you can clear the selected Item.

Me.lstSomeName = Null

The RowSource is the value list. If the Listbox is bound, the instruction above will clear the selected value.

If you are working with a multi-value field, go to jail. Do not pass GO. The multi-value fields are nothing but trouble. Use a properly normalized table with a child table so you can select multiple items. Display it as a subform.
 
just make the listbox "unbound"

Me.listbox.RowSource = ""
 
try it first and forget the op, maybe it is Not what he meant.
My Windows is not working at the moment so couldn't test.

I just wondered whether when you you do Set Me.listbox.Recordset = rs, then perhaps the RowSource is still vbNullstring and you have to set its Recorsdet = Nothing to clear it?
 
It comes up if you start to type it in Access though? :)
 
Yes, I only have 2007, but I entered it, intellisense made it propercase. My understanding is if it was not recognised, it would remain lowercase as I entered it?

In hospital car park atm, so cannot make any further tests.
 
OK, just got home and tried again.
Whilst Clear does not appear in the dropdown, it changes from lowercase to propercase?

That is what confused me.:(

You will have to take my word for it, that I did not change the second pic manually. :)
 

Attachments

  • Clear_LC.PNG
    Clear_LC.PNG
    3.9 KB · Views: 111
  • Clear_PC.PNG
    Clear_PC.PNG
    3.9 KB · Views: 111
I must be missing something. What is the reason for wanting to remove ALL values from the RowSource? There is no point to a combo or list box if it has no selection options.

You can always replace the RowSource with a query that returns no rows. Is that what you want?
 
Last edited:
@Gasman. If "clear" is a method of some other object I believe intellisense will change the capitalization even if not a property or method of the current combobox object.
 
Hi,
For clarity, by clear I am meaning that I want to empty the listbox of any previous results - I want a blank listbox.

Code:
Set lstResults.Recordset = Nothing
Also doesn't do anything. Bit strange really as all the previous results are still in the listbox even though the recordset is nothing you may have expected it to have cleared out its contents...
 

Users who are viewing this thread

Back
Top Bottom