How to create combo a-z to sort list box?

Spam808

Registered User.
Local time
Yesterday, 22:23
Joined
Dec 3, 2018
Messages
55
I would like to create a combo box that sorts a-z or z-a? How should I go about this to sort data in a list box?
 
If you only have two options, it might be better to use a radio or toggle button. Just a thought...
 
How is that response a help?
 
Hi. It was an attempt to help make the problem easier if not the solution itself. For example, if you think about the amount of effort to create a combobox with two options as compared to using a single toggle button, which do you think would be easier? As I said though, it was just a thought. I wasn’t trying to tell you that it’s the only way to go and you must do it. As my sig below says, it’s just my 2 cents...
 
How do you do this?

If I was to help, I would say "click here, and select option a. Type code to make the combo box work."

That is helping someone
 
If I was to help, I would say "click here, and select option a. Type code to make the combo box work."
That is helping someone
You need to shut up. You have provided nothing to this forum. Look at your Thanks (0) versus DBGuy. You want nothing but to be spoon fed. That is not the way it works. He provided good advice. So do some work or go away. You are a leach.
 
I would like to create a combo box that sorts a-z or z-a? How should I go about this to sort data in a list box?

So far, all good suggestions offered.

Create an unbound combo box,
Row Source: "A-Z", "Z-A" (whatever, could be Asc, Desc)
Row Source Type: Value List

Write code in the AfterUpdate event of the combo box, that depending on the selection made, will reset the RowSource of the listbox, then in same AfterUpdate event, requery the said listbox.

This should get you started.
 
Try looking up spam musubi, that what is spam.
 
If you only have two options, it might be better to use a radio or toggle button. Just a thought...
Wondering if a lot of what follows your comment stems from a misunderstanding. I read it as "sort A to Z or sort Z to A" meaning inclusive and either ascending or descending. Then again, I have no history with the OP so please ignore this if I'm out of place.
The combo row source (sql or query with ORDER BY clause) can do the sorting, assuming the combo row source isn't just a value list.
 
Last edited by a moderator:
Hi Micron. You could be correct. The way I read the OP is there’s a desire to use a dropdown with only two items in it (Ascending and Descending) with the intent to sort a Listbox based on the selection made in the Combobox. Are you saying the request is to actually have an item for each letter in the alphabet (26 rows, at least)?
 
To me, A-Z just meant alphabetical sort rather than numeric. I figured listbox just meant combo list, otherwise I don't see a connection between a combo and a list box. Details are vague.
 
theDBguy, that is correct. The combo box would be just two items base on a value list of a-z or z-a to sort a listbox alphabetically. I am assuming the only way to accomplish this would be with a requery. Is there an example or tutorial out there for this solution?
 
theDBguy, that is correct. The combo box would be just two items base on a value list of a-z or z-a to sort a listbox alphabetically. I am assuming the only way to accomplish this would be with a requery. Is there an example or tutorial out there for this solution?
Hi. In the AfterUpdate event of the combobox, you could try something like:
Code:
If Me.ComboboxName="a-z" Then
    Me.Listbox.RowSource="SELECT * FROM TableName ORDER BY FieldName
Else
    Me.Listbox.RowSource="SELECT * FROM TableName ORDER BY FieldName DESC
End If
But as I was saying initially, if you use a Toggle button instead, your Click event might look something like this:
Code:
If Me.ToggleButton Then
    Me.Listbox.RowSource="SELECT * FROM TableName ORDER BY FieldName
Else
    Me.Listbox.RowSource="SELECT * FROM TableName ORDER BY FieldName DESC
End If
The difference being adding a Toggle button just seems simpler than setting up a Combobox. And for the user, it's one click versus two. Again, it's just a thought...
 
Can have code in combobox (or radio button Option Group or Toggle button) AfterUpdate event that sets the listbox RowSource. Like:

Me.listbox.RowSource = "SELECT ID, field FROM table ORDER BY field " & IIf([Combo49] = "Ascending", "", "DESC") & ";"

But what purpose does this serve? How many items are in this listbox?
 
Last edited:
I'd use something above the listbox and cycle the sort via click or double click. Maybe a button and alter its caption accordingly. Dont see the sense in a combo with a list just to apply a sort.
 
Thank you everyone for your help, and thank you theDBguy
 
Thank you everyone for your help, and thank you theDBguy
Hi. You’re welcome. We’re all happy to assist. Even if sometimes it doesn’t appear so, we do try to help. Cheers!
 

Users who are viewing this thread

Back
Top Bottom