remove item from current item in list box

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,
 
D

Damon Heron

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
 
I

inungh

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,
 
D

Damon Heron

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top