Filter rowsource of combobox

Kayleigh

Member
Local time
Today, 20:52
Joined
Sep 24, 2020
Messages
709
Hi
What is the best way to filter a listbox 's rowsource. I would like to show all results in listbox onload but if user selects AM/PM, it should filter the listbox to only display those results.
I have been using dynamic SQL strings onChange which work but do not save the data formats as I specify in the query.
 
If you simply use a saved query, does the format stay intact?
 
Last edited:
Yes
 
I see. Have you tried using a TempVar for your criteria and then simply requery the listbox? You can update the TempVar in the Change event.
 
I do something similiar if I'm reading this right.
I use an option group with selections of "open", "closed", and "all". The default I use is "Open" but you could set it to "all". In my code I use a select case on the OG and set the rowsource accordingly. Something along these lines:

Code:
Private sub SetLists()

Select Case Me.Frame0

    Case 1

        Me.lstClients.RowSource = "Select PartyID, LastName & ', ' & FirstName as vName from tblPeople where PartyID in(" & strOpen & ") order by LastName & ', ' & FirstName"

    Case 2

        Me.lstClients.RowSource = "Select PartyID, LastName & ', ' & FirstName as vName from tblPeople where PartyID in(" & strClosed & ") order by LastName & ', ' & FirstName"


    Case 3
        Me.lstClients.RowSource = "Select PartyID, LastName & ', ' & FirstName as vName from tblPeople where PartyID in(" & strAll & ") order by LastName & ', ' & FirstName"

    End Select

End Sub

I then call SetLists in the onload event, the OG's afterupdate event, and where ever else I need it.
 
I do the same as Moke123. In multi-column lists, I also put a sort ascending/descending, toggled by double clicking the column header label, on relevant columns eg I might put that on a suburb column but not on the street name.
 

Users who are viewing this thread

Back
Top Bottom