Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2011

    Unanswered: Listbox Results From Query With Multiple Criterias Based on Items Selected

    I am trying to populate listbox2 based on a query with criterias that are dependent on the items selected in listbox1. I am guessing that I will have to write a for loop, but I have no idea how to do so. Below is what the SQL code would look like.

    select distinct clause
    from GroupClauses
    where Group_Name = 'List Item Selected 1' or Group_Name =List Item Selected 2'  or Group_Name =List Item Selected n'

  2. #2
    Join Date
    Mar 2009
    Provided Answers: 14
    Try this (replacing List0 by the name of the list on your form):
        Dim varItem As Variant
        Dim strSQL As String
        For Each varItem In Me.List0.ItemsSelected
            If Len(strSQL) > 0 Then strSQL = strSQL & ", "
            strSQL = strSQL & "'" & Me.List0.ItemData(varItem) & "'"
        Next varItem
        strSQL = "SELECT DISTINCT clause " & _
                "FROM GroupClauses " & _
                "WHERE Group_Name IN ( " & strSQL & " );"
    If Group_Name is a numeric (seems very unlikely with such a name!) remove the single quotes around the values (strSQL = strSQL & Me.List0.ItemData(varItem))
    Have a nice day!

Posting Permissions

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