+ Reply to Thread
Results 1 to 2 of 2

Cannot remove item from collection

  1. #1
    Kou Vang
    Guest

    Cannot remove item from collection

    I am having trouble removing items from a list box. Here is my code:

    Option explicit:

    Dim I As Integer

    If LstOLd.ListCount >= 1 Then
    If LstOLd.ListIndex = -1 Then
    LstOLd.ListIndex = _
    LstOLd.ListCount - 1
    End If

    LstOLd.RemoveItem (LstOLd.ListIndex)

    LstNew.RemoveItem (LstNew.ListIndex)
    LstColor.RemoveItem (LstColor.ListIndex)
    End If

    I also found this:

    An error occurred while attempting to remove an item from a collection.
    Typically, this is a result of the following:

    Attempting to remove a table while it is participating in a relationship
    with another table.
    Attempting to remove a column while it is defined as a Foreign Key in a
    relationship.
    Attempting to remove a column that is part of another columns expression.
    Attempting to remove a column that is involved in a relationship.
    To correct this error

    Remove the constraint that this collection item participates in.

    Is this perhaps my problem? Thanks.




  2. #2
    George Nicholson
    Guest

    Re: Cannot remove item from collection

    On which line does the error occur? When you try to remove an item from
    LstOld, or when you try to remove an item from one of the other boxes? If
    the latter, it may be because ListIndex for those boxes is -1 or otherwise
    invalid for RemoveItem. Your code covers that possibilty for lstOld, but not
    the other 2 boxes.

    HTH,
    --
    George Nicholson

    Remove 'Junk' from return address.


    "Kou Vang" <[email protected]> wrote in message
    news:[email protected]...
    >I am having trouble removing items from a list box. Here is my code:
    >
    > Option explicit:
    >
    > Dim I As Integer
    >
    > If LstOLd.ListCount >= 1 Then
    > If LstOLd.ListIndex = -1 Then
    > LstOLd.ListIndex = _
    > LstOLd.ListCount - 1
    > End If
    >
    > LstOLd.RemoveItem (LstOLd.ListIndex)
    >
    > LstNew.RemoveItem (LstNew.ListIndex)
    > LstColor.RemoveItem (LstColor.ListIndex)
    > End If
    >
    > I also found this:
    >
    > An error occurred while attempting to remove an item from a collection.
    > Typically, this is a result of the following:
    >
    > Attempting to remove a table while it is participating in a relationship
    > with another table.
    > Attempting to remove a column while it is defined as a Foreign Key in a
    > relationship.
    > Attempting to remove a column that is part of another columns expression.
    > Attempting to remove a column that is involved in a relationship.
    > To correct this error
    >
    > Remove the constraint that this collection item participates in.
    >
    > Is this perhaps my problem? Thanks.
    >
    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1