How to sort a listbox whose "Row Source Type" is "Field List"

Hello Experts,

I have a list box in my Form. The "Row Source Type" of this listbox is set to "Field List" and during run time the list box shows the headers/fields of a query. The query has many fields and hence I would like the values appearing in the listbox to appear in sorted order. Please help.

Please let me know if you need any further information. Many thanks for your help.

LVL 12
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan Van VleetBankerCommented:
Please be more specific, I know you cannot make a query from a data set like that, but you could probably make it into its own field..

For example, in one database I made, I had the tables: Employees, Products, and Transactions.

So, on the transactions form, there was a listbox of employees and products, in this way, you would be able to create a query of transactions, based on which employee or which product (or both) was in the transaction, instead of just an numerical list of transaction #s..

Hope this helps, if not, be more specific, include your database if possible, and let me know what you're trying to accomplish.

Restated: Sort the run-time "Field List" entries in the listbox?
If so, the only way I know to do that would be to use an SQL SELECT statement as the listbox's .RowSource and order the fields the way you want them.
For example, tblExample has fields fldA1, fldB1, fldA2 (notice the order)
If I set listbox.RowSource = tblExample, my run-time listbox entries will be
If I set listbox.RowSource = SELECT fldA1, fldA2, fldB1 FROM tblExample;, my run-time entries will be
It's manual, and therefore not ideal, but it works. :-)
BTW, using the ORDER BY clause as in "SELECT * FROM tblExample ORDER BY blah;" won't work because ORDER BY sorts records, not fields.

Using a table or query object as the .RowSource leaves you at the mercy of the field order in the object.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sstampfAuthor Commented:
Thanks for taking out time to read my question and post comments. I would consider the answer to be "What you are looking for is not possible".
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.