Filter ListBox for Multiple Groups

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Filter ListBox for Multiple Groups

Post by burrina »

I need to be able to filter my list box for multiple groups,individual or all. Your ideas would be very much appreciated. Having a brain dead day!
Last edited by burrina on 21 Oct 2014, 16:15, edited 1 time in total.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Filter ListBox for Multiple Groups

Post by Rudi »

How do you propose to filter for an individual?
A second dropdown with ONLY email address, or at least two pieces of info; group AND email address listed in the dropdown.
One for groups and <<ALL>> and the other for individual and <<ALL>>
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
HansV
Administrator
Posts: 78446
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Filter ListBox for Multiple Groups

Post by HansV »

If you want to be able to select multiple groups, you'll have to use a multi-select list box instead of the combo box cbogroup.
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Filter ListBox for Multiple Groups

Post by burrina »

I tried adding a new list box and then a requery of the list box for the results with no success. What am I missing?
Changed the record source to the below to reflect the new list box.

SELECT tblEmailTo.eemailto, tblEmailGroup.egroup, tblEmailTo.eemailaddress FROM tblEmailGroup INNER JOIN tblEmailTo ON tblEmailGroup.eGroupID = tblEmailTo.eGroupID WHERE (((tblEmailGroup.egroup) Like "*" & [lstgrps]));

User avatar
HansV
Administrator
Posts: 78446
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Filter ListBox for Multiple Groups

Post by HansV »

See if the attached version does what you want (I didn't bother about the details, I just changed the combo box to a list box and added the code needed to select groups).
MultipleGroups.zip
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Filter ListBox for Multiple Groups

Post by burrina »

Almost. How can I then after DeSelecting make the ListBox show All records?

User avatar
HansV
Administrator
Posts: 78446
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Filter ListBox for Multiple Groups

Post by HansV »

Change the On Click event of cbogroup to

Code: Select all

Private Sub cbogroup_Click()
    Dim varItem As Variant
    Dim strIn As String
    
    For Each varItem In Me.cbogroup.ItemsSelected
        strIn = strIn & "," & Me.cbogroup.ItemData(varItem)
    Next varItem
    If strIn <> "" Then
        strIn = Mid(strIn, 2)
        Me.lstlist.RowSource = "SELECT * FROM qryEmailClientsByGroup WHERE eGroupID In (" & strIn & ")"
    Else
        Me.lstlist.RowSource = "SELECT * FROM qryEmailClientsByGroup"
    End If
End Sub
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Filter ListBox for Multiple Groups

Post by burrina »

Thank You so much! Exactly what I was after.