remove item from current item in list box

  • Thread starter Thread starter iccsi
  • Start date Start date
I

iccsi

I would like to remoce an item from list box and I use the following
code

lstMyList.RemoveItem (lstMyList.ListIndex)

Which works first time, but it does not remove item when I run the
second time.

should it remove the item selected in the list box every time?


Your information is great appreciated,
 
This is a hard-coded value list? Not sure what you mean by running a second
time - Do u mean you close the form and the items re-appear? That would be
normal, unless you write code to amend the value list.

Damon
 
This is a hard-coded value list?  Not sure what you mean by running a second
time - Do u mean you close the form and the items re-appear?  That would be
normal, unless you write code to amend the value list.

Damon










- Show quoted text -

Thanks for the message,
It is value list, but added at run time by my SQL.
No, I did not close the form. I continue to remove from list box
without do any actions on the form.

Thanks again,
 
How are you adding the items? Here is an example in the form load event:

Private Sub Form_Load()
Dim i As Integer
Dim DB As DAO.Database
Dim rs As DAO.Recordset
Set DB = CurrentDb
Set rs = DB.OpenRecordset("tblMyList", dbOpenDynaset)
Do Until rs.EOF

'myblendArray(i) = rs!ListName
Me.Listbox1.AddItem rs!ListName, i
i = i + 1
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set DB = Nothing

End Sub

then remove the items by the listbox click event:

Listbox1.RemoveItem (Listbox1.ListIndex)

Works for me!

Damon



This is a hard-coded value list? Not sure what you mean by running a
second
time - Do u mean you close the form and the items re-appear? That would be
normal, unless you write code to amend the value list.

Damon










- Show quoted text -

Thanks for the message,
It is value list, but added at run time by my SQL.
No, I did not close the form. I continue to remove from list box
without do any actions on the form.

Thanks again,
 
Back
Top