Remove Item from the List

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!
I would like to remove an item from the List when double click on the List.
The Listbox have these properties:
RowSourceType = Table/Query
Row Source = Query2

In the List0_DblClick event procedure I have this:
List0.RemoveItem (List0.ListIndex)

But it returns an error: "The RowSourceType must be set to 'Value List' to
use this method"

What am I missing? Can someone help?
 
You can't use RemoveItem (nor AddItem) if you're using a query to populate
the listbox (or combobox). Those methods only work when you provide a list
of values as the Row Source (with a RowSourceType property of Value List)

One approach would be to add a binary field to the underlying table, and
have your query only return those rows for which the binary field is True.
You'd then set the field to False when you want to remove the entry from the
list, and issue a Requery.
 
Thanks. Do you have any sample code?

Douglas J Steele said:
You can't use RemoveItem (nor AddItem) if you're using a query to populate
the listbox (or combobox). Those methods only work when you provide a list
of values as the Row Source (with a RowSourceType property of Value List)

One approach would be to add a binary field to the underlying table, and
have your query only return those rows for which the binary field is True.
You'd then set the field to False when you want to remove the entry from the
list, and issue a Requery.
 
For what?

You need to run an Update query to set the binary field appropriate in your
underlying table.

Assuming you've got a reference set to DAO, that would be something like:

Dim strSQL As String

strSQL = "UPDATE MyTable " & _
"SET MyBinaryField = False " & _
"WHERE MyIndex = " & IdToRemove
CurrentDB.Execute strSQL, dbFailOnError

You then issue a Requery on the listbox:

Me!MyListBox.Requery

Without knowing anything about your tables, etc., that's about as specific
as I can get.
 
Back
Top