Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EMPTYING A LISTBOX

Status
Not open for further replies.

619Ghz

Programmer
Dec 3, 2003
17
US
I need to empty my listbox..
I tried list1.rowsource = "" but it creates a row with spaces on it...

I tried list1.rowsource = null; but is not accepted..

I wanted to totally empty the box, without anything in it..
no empty spaces, nothing...

help? Thanks!!

 
So, I guess nobody can help with this one huh?
Well...
 
Sorry, still gives an empty row with spaces...
 
Try:
Code:
List1.RowSource = "SELECT null from Tablename"


Hoc nomen meum verum non est.
 
That actually gave me a bunch of empty rows...
but if you create a blank table and use that for this statement.. it works..

but, there's gotta be a much automated way, right?

 
What ver of Access are you using and how are you getting the values for your listbox?
Are you using vba, a query in the row source or is it bound to a table?
 
Acces 97, value is from a query statement,
vba, list1.rowsource ' "SELECT this FROM that":
The problem is, whenever I clear all the fields in the list(using rowsource = ""), there is this column line(gray line) for one empty row, which I want to remove. So I want to totally empty the list whenever I clear items in it...

thanks for any help...

 
I sorry but I really thought that the Empty would help you out. I tried it in Acc97, 2000, and XP and it worked in all 3.
Good luck and I hope you find a solution soon. Please post up what the answer is when you do find it.
 
Why don't you try the following:

Dim I as Long
If Listbox1.ListCount>0 Then
For I = 1 to Listbox1.ListCount
Listbox1.RemoveItem 0
Next I
End If

Keep in mind that the RowSource Property is in String Data Type, so using the code:

Listbox1.RowSource = ""

Should work for the most part. However, there is one more thing you can try. Try setting the RowSourceType to "ListValue" when you want it empty as opposed to "Table/Query" when it's source is from a table/query (including SQL Statements).

2 other things to consider about the queries, first is what method as I assume for the most part, you already have considered this.

Methods:

SELECT
INSERT(Add)
MAKE-TABLE
UPDATE
DELETE
UNION

Second is what type:

Types:

DYNASET (Jet/DAO Only)
SNAPSHOT
FORWARD ONLY
DYNAMIC (ODBC Only)

Main reason why I left out TABLE is cause that's dealing with recordsets along with the other types.

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
When the going gets tough, the tough gets going.
 
Thanks for all your help, but I guess the easiest way to do this, so far, is creating a blank table then,
SELECT null FROM blank...

 
How about this:

List1.RowSource = "SELECT * WHERE FALSE"

John

Imagining being on the DNA software development team!!!
 
Put a WHERE condition of your current rowsource of WHERE 0=1.

0 never equals 1, so it will return no records.

Ed Metcalfe.

Please do not feed the trolls.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top