Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27
  1. #16
    tmcrouse is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Apr 2009
    Posts
    169

    I did run across that in my research but not sure how to apply it to 11 multi-select listboxes. I don't have just 1 multi-select box for the end user to choose from, there are 11 and I am just completely at a loss. I am a SAS person and it has been since 2002 I have done VB but in my last job I got into some Excel Marco VB stuff last summer but extremely basic.

  2. #17
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Do you want to allow multiple selections from each listbox? Never seen multiple IN operators in a single SQL statement. Not sure is possible or even sensible. The construct would be like:

    Field1 IN(item1, ..., item#) AND Field2 IN(item1, ..., item#) AND Field3 IN(item1, ..., item#) ... etc.

    Or maybe

    Field1 IN(item1, ..., item#) OR Field2 IN(item1, ..., item#) OR Field3 IN(item1, ..., item#) ... etc.

    The code isn't that much more difficult. Just means looping code for each listbox and concatenating the strings produced by each listbox.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #18
    tmcrouse is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Apr 2009
    Posts
    169
    Yeah it is crazy. I would think if it was done a lot there would be some great reference material out there. So that tells me you are right about it not being sensible, however..........one has a hard time arguing with mgmnt and winning. Let me attempt that and see what happens.

  4. #19
    tmcrouse is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Apr 2009
    Posts
    169
    I have seen the allenbrowne and will see if I can incorporate any of this to make it work.

  5. #20
    tmcrouse is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Apr 2009
    Posts
    169
    Ok. I think it is time to get MS to help. I am going to send my code to them and see if they can help me because nothing I do works.

  6. #21
    tmcrouse is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Apr 2009
    Posts
    169
    OK, so I STILL cannot figure this out. I followed what Allen Browne did, but still is not working. I am going to have a nervous breakdown. 2wks almost working on this 1 item.

  7. #22
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Do you want to provide latest version of db with the attempted code?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #23
    tmcrouse is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Apr 2009
    Posts
    169
    No, I am just spinning my wheels. I am just going to pay MS to help me.

  9. #24
    tmcrouse is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Apr 2009
    Posts
    169
    WOW. What an experience. Ok. This is solved and I hope this will help others out:

    Incase anyone needs a solution for multiple multi-listboxes on a form they are using to filter a query that is not attached to the multi-listboxes but only the form and they want end-users to have the ability to filter and see the results, MajP at Tek Tips helped me solve the problem I posted on here. Here is the information to help people out.

    1) Use continuous form.
    2) You multi-listboxes need to be in the header selection so after selection your results are in the details.
    2) Have a command buton to see results and a command button for clearing what an end-user selected.
    3) Use functions to build what you need for the filters.
    4) Put your labels you use to search your query in the header section as well and then the textboxes to display results in the details section. This way you labels will not continuously appear. Only the data will.


    Code:
    Private Sub cmdReset_Click()
      Dim ctrl As Access.Control
      Dim itm As Variant
      For Each ctrl In Me.Controls
        If ctrl.ControlType = acListBox Then
          If ctrl.MultiSelect = 0 Then
            ctrl = Null
          Else
            For Each itm In ctrl.ItemsSelected
                ctrl.Selected(itm) = False
            Next
          End If
        End If
      Next ctrl
      Me.Filter = ""
      Me.FilterOn = False
    End Sub
    
    Private Sub cmdResults_Click()
       Dim FormFilter As String
       FormFilter = GetFilterFromListBoxes
       Debug.Print FormFilter
       Me.FilterOn = False
       Me.Filter = FormFilter
       Me.FilterOn = True
    End Sub
    
    Public Function GetFilterFromListBoxes() As String
      Dim lst As Access.ListBox
      Dim ctrl As Access.Control
      Dim fieldName As String
      Dim fieldType As String
      Dim TotalFilter As String
      Dim ListFilter As String
      Dim itm As Variant
      'Each listbox needs a tag property with the  field name and the field type
      'Seperate these with a ;
      'The types are Text, Numeric, or Date
      For Each ctrl In Me.Controls
         If ctrl.ControlType = acListBox Then
           fieldName = Split(ctrl.tag, ";")(0)
           fieldType = Split(ctrl.tag, ";")(1)
           For Each itm In ctrl.ItemsSelected
           If ListFilter = "" Then
             ListFilter = GetProperType(ctrl.ItemData(itm), fieldType)
           Else
             ListFilter = ListFilter & "," & GetProperType(ctrl.ItemData(itm), fieldType)
           End If
           Next itm
           If Not ListFilter = "" Then
              ListFilter = fieldName & " IN (" & ListFilter & ")"
           End If
           If TotalFilter = "" And ListFilter <> "" Then
             TotalFilter = ListFilter
           ElseIf TotalFilter <> "" And ListFilter <> "" Then
             TotalFilter = TotalFilter & " AND " & ListFilter
           End If
           ListFilter = ""
         End If
      Next ctrl
      GetFilterFromListBoxes = TotalFilter
    End Function
    
    Public Function GetProperType(varItem As Variant, fieldType As String) As Variant
      If fieldType = "Text" Then
        GetProperType = sqlTxt(varItem)
      ElseIf fieldType = "Date" Then
        GetProperType = SQLDate(varItem)
      Else
        GetProperType = varItem
      End If
    End Function
    
    Public Function sqlTxt(varItem As Variant) As Variant
      If Not IsNull(varItem) Then
        varItem = Replace(varItem, "'", "''")
        sqlTxt = "'" & varItem & "'"
      End If
    End Function
    
    Function SQLDate(varDate As Variant) As Variant
         If IsDate(varDate) Then
            If DateValue(varDate) = varDate Then
                SQLDate = Format$(varDate, "\#mm\/dd\/yyyy\#")
            Else
                SQLDate = Format$(varDate, "\#mm\/dd\/yyyy hh\:nn\:ss\#")
            End If
        End If
    End Function
    My form is linked to my query.
    My multi-listboxes are linked to the tables within my database that house all the information. Such as State would house all the states so end-users would be able to see all the states. This does not mean the end-user will see all the states in the results. They will only see what is in my query. My query is querying fields from my main table I want to show on my results based on what they filter for. Hope this makes sense.

    I hope this helps those out there that have requests for multiple multi-listboxes.............Was a 2wk challenge for me trying to figure this out and I thank MajP so assisting in the solution.
    Last edited by June7; 05-15-2014 at 10:50 AM.

  10. #25
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Glad you figured it out but I am kicking myself for not noticing the listboxes where in detail section. Might have cut days off your experience if I had.

    So did you eliminate form/subform and just go with a solo form?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #26
    tmill29 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    3
    What a concept

  12. #27
    tmcrouse is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Apr 2009
    Posts
    169
    I ended up using a continuous form.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Multiple Listboxes on form with subform
    By cbrsix in forum Programming
    Replies: 12
    Last Post: 08-01-2013, 03:35 PM
  2. Multiple Listboxes in Search Form
    By cbrsix in forum Programming
    Replies: 6
    Last Post: 05-03-2013, 12:11 PM
  3. Replies: 3
    Last Post: 04-16-2013, 08:44 AM
  4. Combining data from multiple listboxes
    By dshillington in forum Access
    Replies: 1
    Last Post: 10-04-2012, 11:53 AM
  5. Multiple Listboxes
    By Butterflies88 in forum Forms
    Replies: 1
    Last Post: 02-11-2009, 10:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums