Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2003
    Posts
    280

    Unanswered: How do you remove items from a listbox?

    I'm having a problem removing certain items on the listbox. I was able to add items to a listbox but not able to delete them. I thought VBA would have something like VB also, like Listbox.RemoveItem string but it dont' have any. Is it because of the REFERENCES that I haven't set to it or is there a way to do it?

  2. #2
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    list35.RemoveItem (0)

    you need to include the item index and set the rowsource type property to valuelist

    I think that should do it.

    have not done it that way in a long time - I usually delte the record where columnid equals coulumn id in the table and the requery the listbox.

  3. #3
    Join Date
    Apr 2003
    Posts
    280
    What references are you using(It's under the Tool menu) because mine not shownig up and i even try typing it in and run. I would get a method not found.

    I usually do it like this listbox.removeitem (listbox.listindex) in Visual basic
    Last edited by lansing; 07-10-03 at 17:18.

  4. #4
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    attach a sample form with the listbox and the items and your code behind the button and I will debug

    As for references - unless I am dealing with sql or another backend
    I always remove the ado reference and use dao (2000 and greater versions)

    cannot see that this would be the issue if infact the intellisense shows you the methods/properties as you type.

  5. #5
    Join Date
    Apr 2003
    Posts
    280
    I'm going to just post up the codes. I just did a small code to test it out.

    listbox name is lstTest

    'This button is to insert items into the listbox.

    Private Sub Command249_Click()
    Dim str As String

    str = str + "1" + ";" + "2" + ";"
    lstTest.RowSourceType = "Value list"
    lstTest.RowSource = str
    lstTest.Requery

    End Sub

    'this button is to delete the item on the listbox which you show me.

    Private Sub Command246_Click()

    lstTest.RemoveItem (0)
    End Sub


    Also, i'm using Microsoft ADO 2.1

  6. #6
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    I am using dao 3.6 and it worked fine for me

    i put "bob" as my valu in the list box

    i used the code
    list35.removeitem(0)
    it was removed

  7. #7
    Join Date
    Apr 2003
    Posts
    280
    I have try the code again with the microsoft DAO 3.6 and still doesn't work. I have went with a different route now by just creating a table and link the listbox to it. this way, I can definately delete it. Thanks anyways.

  8. #8
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    weird

    I did mention that the best way to control it is the table/query method - I prefer that method

    If I were you I would be racking my brains out on why it does not work - like putting in breaks and looking at values I step through - stuff like that drives me crazy.

    good luck

  9. #9
    Join Date
    Apr 2003
    Posts
    280
    it drives me crazy on why it didn't work. I'm will be still thinking about this until i get it to work. I have use the step through for all my code that doesn't work correctly. That's one thing I like about vb so much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •