Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox ItemsSelected Issue

Status
Not open for further replies.

Jean9

Programmer
Joined
Dec 6, 2004
Messages
128
Location
US
On my form is a single listbox that when a value is selected in a combobox object, code is executed to select certain list items based on the combobox selection. The issue I am having occurs at the time when the user de-selects one or more items in the list and leaves other items selected (or pre-selected via the code). When subsequent code loops through the listbox items to see what has been selected, it does not "see" the list box items that the user left as selected (or pre-selected via the code originally). It negates the purpose of setting the selected items via code if the user has to re-select them in order for code to recognize the item as selected. What code can be used to see the "selected" items that were initially set as selected via the code?
Thanks,
J9
 
And...it looks like the last 'deselected' item is the item that the code thinks is 'selected'...
 
the item that the code thinks is 'selected'
Which code ?
Have a look at the ItemsSelected collection of a multiselect ListBox.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Below is the code for original selection
Code:
    With LstAPPS
        For i = 0 To .ListCount - 1
            ' Find occurences of User Access and select list item
            If UserHasPerms(sUSERID, .Column(1, i)) Then
                .Selected(i) = True
                .Enabled = True
            End If
        Next i
    End With

Below is the code for the subsequent check of selected item after user has deselected one or more items from the list but not all items:
Code:
For Each VARPATH In .ItemsSelected
    sSQL = "Delete * from " & .Column(1) & " where UserName ='" & Me.CbxUSERID & "'"
    DoCmd.RunSQL (sSQL)
Next VARPATH

This code is being executed for items that were last selected OR deselected rather than "seeing" the selected items (that may appear in the list as selected and sequentially before the last selected or deselected item) that were set as selected in the first code snippet.

J9
 
You don't use VARPATH in your loop ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
VARPATH is just a variable dimmed as variant. What method should be used to execute code for just selected (highlighted) items in the list?
J9
 
Nevermind, I understand what you mean. I should have used VARPATH in the "Delete * from " & .Column(1)" to read Delete * from " & .Column(1, VARPATH).

Got it.

Thanks!
J9
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top