Results 1 to 5 of 5
  1. #1
    dreamnauta is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2011
    Posts
    16

    Exclamation Deleting a ListBox Selection

    In my efforts to become more efficient at VBA, I am requesting help from you guru's once again



    I have a bound Combo box. When the user makes a selection, the selection (String) is then added to a List box. Although I don't like the idea of a bound Combo box I am going to stick with it for now. However, here is my question. The List Box receiving the values from the bound combo box is not designating the item as a list box item. I want the user to be able to delete an item in the list. For example when I run this code

    Code:
    Dim i As Integer
    For i = listBox.ListCount - 1 To 0 Step -1
       If listBox.Selected(i) Then listBox.RemoveItem i
    Next i
    End Sub
    I get a runtime error : "unable to remove item, 0 not found in list"

    Is the listBox not recognizing the data because it is from a bound query?

    How do I resolve this problem?

    Any help is much appreciated!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    I think RowSource property setting conflicts with AddItem and RemoveItem.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    dreamnauta is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2011
    Posts
    16
    Is there anyway to work around this, or should I just go ahead and make an unbound selection list, and add the entries manually?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    No workaround that I know of. Must do one or the other.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    dreamnauta is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2011
    Posts
    16
    Thanks for your help! It wasn't a conflict with the row source, just a logic error on my part, I told access to look at the wrong listbox!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Deleting multiple records selected in a Listbox
    By ankitmehtta in forum Access
    Replies: 4
    Last Post: 11-08-2011, 01:20 PM
  2. Replies: 1
    Last Post: 11-05-2010, 05:49 PM
  3. Cancel Selection Event for ListBox
    By is49460 in forum Forms
    Replies: 2
    Last Post: 08-04-2010, 05:53 PM
  4. Replies: 2
    Last Post: 08-03-2010, 10:16 AM
  5. Cancel listbox selection
    By vba-dev in forum Access
    Replies: 0
    Last Post: 10-26-2009, 12:18 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums