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.
 
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: 193
  • Clear_PC.PNG
    Clear_PC.PNG
    3.9 KB · Views: 177
@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...
 
Also, for reference, this is not a multiselect listbox (not sure whether this matters though as I'm not looking to clear the selected entries but clear the entire listbox of everything!!)
 

Users who are viewing this thread

Back
Top Bottom