Results 1 to 1 of 1

Thread: Almost there

  1. #1
    Join Date
    Apr 2008
    Posts
    10

    Unanswered: ListBox MultiSelect Link to Query

    I found the following code to make a listbox send multiple choices to a text box. I want the code to send multiple choices to a query and open the query.
    The query is titled qryStudentListing2. The field that should relate to ListBox1 is qryStudentListing2.Class. I don't know where to put the query reference in the following code. It now sends the choices to a textbox called MySelections

    Here is the code:
    Private Sub Form_Current()
    Dim oItem As Variant
    Dim bFound As Boolean
    Dim sTemp As String
    Dim sValue As String
    Dim sChar As String
    Dim iCount As Integer
    Dim iListItemsCount As Integer

    sTemp = Nz(Me!mySelections.Value, " ")
    iListItemsCount = 0
    bFound = False
    iCount = 0

    Call clearListBox

    For iCount = 1 To Len(sTemp) + 1
    sChar = Mid(sTemp, iCount, 1)
    If StrComp(sChar, ",") = 0 Or iCount = Len(sTemp) + 1 Then
    bFound = False
    Do
    If StrComp(Trim(Me!NamesList.ItemData(iListItemsCount )), Trim(sValue)) = 0 Then
    Me!NamesList.Selected(iListItemsCount) = True
    bFound = True
    End If
    iListItemsCount = iListItemsCount + 1
    Loop Until bFound = True Or iListItemsCount = Me!NamesList.ListCount
    sValue = ""
    Else
    sValue = sValue & sChar
    End If
    Next iCount
    End Sub

    Private Sub clearListBox()
    Dim iCount As Integer

    For iCount = 0 To Me!NamesList.ListCount
    Me!NamesList.Selected(iCount) = False
    Next iCount
    End Sub

    Private Sub testmultiselect_Click()
    Dim oItem As Variant
    Dim sTemp As String
    Dim iCount As Integer

    iCount = 0

    If Me!NamesList.ItemsSelected.Count <> 0 Then
    For Each oItem In Me!NamesList.ItemsSelected
    If iCount = 0 Then
    sTemp = sTemp & Me!NamesList.ItemData(oItem)
    iCount = iCount + 1
    Else
    sTemp = sTemp & "," & Me!NamesList.ItemData(oItem)
    iCount = iCount + 1
    End If
    Next oItem
    Else
    MsgBox "Nothing was selected from the list", vbInformation
    Exit Sub 'Nothing was selected
    End If

    Me!mySelections.Value = sTemp
    End Sub

    Private Sub clrList_Click()
    Call clearListBox
    Me!mySelections.Value = Null
    End Sub

    Any suggestions about how to alter this code would be SO helpful.
    Ronna
    Last edited by knowshowrosegrows; 12-12-12 at 10:27. Reason: More descriptive Title

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
  •