Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2010
    Location
    Springfield. MA
    Posts
    3

    Angry Unanswered: itemsselected always empty

    I 've searched the forum for this and read most all of the replies and tried all of the suggestions but to no avail. I have a module that loads a list of file names into a listbox. Works just great. I want to select one of the file names and open and process the file. My itemsselected is always empty. I've tried both code examples in the click event of the listbox :

    Dim i As Integer, selfile As Variant

    MsgBox " " & Me!eanFileList.ItemsSelected.Count '<<=== is always 0
    'Build the IN string by looping through the listbox

    ' For i = 0 To Me.eanFileList.ListCount - 1
    ' If Me.eanFileList.Selected(i) Then
    ' selfile = Me.eanFileList.Column(0, i)
    ' End If
    ' selfile = Me.eanFileList.Column(0, i)
    ' Next i

    For Each selfile In Me.eanFileList.ItemsSelected
    Debug.Print Me.eanFileList.Column(0, selfile)
    Next selfile

    selfile is always empty - any ideas ?

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    And you've made a selection? That's curious, as those methods look fine. Can you post the db?

    I have a bunch of family in your area. Many moons ago I lived with my uncle in Agawam for a year.
    Paul

  3. #3
    Join Date
    Apr 2010
    Location
    Springfield. MA
    Posts
    3
    How do I post the db ? attach it ?

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    ItemsSelected only works if the MultiSelect property of the listbox is different from zero (i.e., if you allow more than one line to be selected in the listbox).
    Have a nice day!

  5. #5
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511
    I had no problems getting the code to work. My list box Multi Select property is set to Simple. Sometimes it makes a difference to delete the problem control and re-create it with the same name. Here is the code I used to display the selected rows count, identify the values of rows selected in a label, and the db is attached.
    Good luck.
    Code:
    Private Sub cmdShowSelected_Click()
    Dim i As Integer, selfile As Variant
    
        Me.lblShowResults.Caption = "Number of rows selected: " & _
            Str(Me.eanFileList.ItemsSelected.Count)
        For i = 0 To Me.eanFileList.ListCount - 1
            If Me.eanFileList.Selected(i) Then
                Me.lblShowResults.Caption = Me.lblShowResults.Caption & _
                    vbCrLf & Me.eanFileList.Column(0, i)
            End If
        Next i
        
        For Each selfile In Me.eanFileList.ItemsSelected
            Debug.Print Me.eanFileList.Column(0, selfile)
            'MsgBox Me.eanFileList.Column(0, selfile)
        Next selfile
    
    End Sub
    Attached Files Attached Files
    Last edited by JerryDal; 04-23-10 at 13:02. Reason: unnecessary line of code

  6. #6
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    There's a manage attachments button in the reply area. Double check the multiselect setting; as Sinndho points out, the Count only works if it's multiselect. I assume it was multiselect based on the other code.
    Paul

  7. #7
    Join Date
    Apr 2010
    Location
    Springfield. MA
    Posts
    3
    W#ell I must have mis-understood the muliselect property of the listbox - mine was set to none - I set it to simple and IT WORKS ! Thanks to everyone for the posts.

Posting Permissions

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