Access 2003 VBA: Return only the index of the last item selected in a ListBox

Posted by Eric D. Johnson on Stack Overflow See other posts from Stack Overflow or by Eric D. Johnson
Published on 2010-03-22T19:00:33Z Indexed on 2010/03/22 19:11 UTC
Read the original article Hit count: 309

Filed under:
|
|

I will preface this with saying, this is my first time using listboxes and earlier posts were criticized for lacking detail. So, all help is greatly appreciated and I hope this is enough information without being overkill.

Currently, I have a listbox updating a junction table with an on click event (iterates through selected items and if they are not in the table it adds them). The list box is also updated by an option group (based on the option group value a query populates the list with the appropriate items and they are selected/highlighted based on the junction table). Also, when items are a "sub-category" the "category" is also selected. This functions perfectly until I ask it to do more...

Problem 1: I need to differentiate "categories" of items from each other. So, I have included a blank item to the list box to add a space between categories. When the blank items are present the listbox does not update the junction table properly and vice versa.

Problem 2: My users want to be able to deselect the "category" under certain circumstances. This is fine, just de-select the "category" after the "sub-category" is selected. However, the "category" is re-selected whenever the listbox is clicked again because it iterates through all entries.

Perceived solution for both problems: Return only the index of the item (de)selected and manipulate accordingly. Is this possible? If so, how?

OR: Should I take a different approach?

© Stack Overflow or respective owner

Related posts about ms-access

Related posts about vba