Share via

Using ListBox.ItemsSelected property value as function argument

Anonymous
2015-11-10T18:34:46+00:00

How can I pass the value of the ItemsSelected property in an Access ListBox to a function which will iterate through the items?  The Help for the ItemsSelected property says that it is a collection, but if I have a function

    function Iterate(Items as Collection)...

and then say

    Iterate(List.ItemsSelected)

I get "Type mismatch" at the point of the function call

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2015-11-10T20:37:17+00:00

    What exactly is it that you're trying to do?  Scott demonstrates one method of how to handle a control and the ItemsSelected property.  If you want to do this outside of the form module, you can pass the control by reference as I mentioned before. 

    Example:

    Function ProcessItemsSelected(ControlObject as Control) As String

        Dim varItem As Variant

        Dim strReturn As String

        strReturn = ""

        For Each varItem In ControlObject.ItemsSelected

            If (strReturn<>"") Then

                strReturn = strReturn & vbCrLf

            End If

            strReturn = strReturn & ControlObject.ItemData(varItem)

        Next varItem

        ProcessItemsSelected = strReturn

    End Function

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2015-11-10T19:07:21+00:00

    Thanks for the replies.  Although it wouldn't be quite satisfactory to do that if you were trying to create a multi-tiered application, would it?  Passing a user interface control to a lower-level function.  I suppose I would have to manually copy the contents of the ItemsSelected property to a regular collection in the user interface event handler.

    Was this answer helpful?

    0 comments No comments
  3. ScottGem 68,830 Reputation points Volunteer Moderator
    2015-11-10T18:59:19+00:00

    Example: Dim frm As Form, ctl As Control Dim varItem As Variant Dim strSelection As String Set frm = Form!frmMyForm Set ctl = frm!lbMultiSelectListbox For Each varItem In ctl.ItemsSelected strSelection = ctl.ItemData(varItem) Next varItem

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2015-11-10T18:37:33+00:00

    You need to pass the control object, then reference the property in your procedure.

    Was this answer helpful?

    0 comments No comments