How can I sort a combo box alphabetically

JTQ911

Registered User.
Local time
Today, 11:35
Joined
Jul 26, 2007
Messages
83
I have a form titled "Run Queries" and on this form I have a combo box "Combobox12" that is populated by all the queries in my database. As of right now, its hard to find the query I want becuase its all in random order. How can I sort these queries in a combobox from A to Z. Thank you in advance. I appreciate it. Here is my code:

Option Compare Database
Option Explicit

Private Sub Combo5_AfterUpdate()

End Sub

Private Sub Combo12_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub Command7_Click()
On Error GoTo Err_Command7_Click

Dim stDocName As String

stDocName = "View Fair Vac Results"
DoCmd.OpenQuery Me.Combo12, acViewNormal, acReadOnly



Exit_Command7_Click:
Exit Sub

Err_Command7_Click:
MsgBox Err.Description
Resume Exit_Command7_Click

End Sub
 
If the combo box Control Source is itself a query you will be able to sort it within the query parameters. If an Alphabetic sort is not what you require, then create a number field and sort on that.
 
Last edited:
I have to tell you this is a most curious post! Your problem is well stated, but you then post your code, which consists of two subs with no code at all, and a third sub in which you have the line

DoCmd.OpenQuery Me.Combo12, acViewNormal, acReadOnly

to open a query, but rather than supplying the name of a query, you supply the name of a combobox! How is that going to work?

At any rate, I think what we really need to see is the Row Source for your combobox.

Linq
 
... and a third sub in which you have the line

DoCmd.OpenQuery Me.Combo12, acViewNormal, acReadOnly

to open a query, but rather than supplying the name of a query, you supply the name of a combobox! How is that going to work?
If the combo box returns the name of the query, it will work just fine. I have used the same method for opening reports. But, the key thing as mentioned is:
At any rate, I think what we really need to see is the Row Source for your combobox.
Because I'll bet that the rowsource is currently a table and not a query based off of that table. If you change from a table to a query in your combo's rowsource you can add sorting to that.

This should help you know how to do it, if you need visual help:
http://www.btabdevelopment.com/main...dsourcefromtabletoquery/tabid/75/Default.aspx
 
This is my row source. I am not sure if it is a table or a query. I was told to enter this into my row source from a fellow forum member based on the question as how to populate my combo box with all the queries in my database


SELECT MSysObjects.Name

FROM MSysObjects

WHERE MSysObjects.Name NOT LIKE "~*" AND
MSysObjects.Type = 5;
 
This is my row source. I am not sure if it is a table or a query. I was told to enter this into my row source from a fellow forum member based on the question as how to populate my combo box with all the queries in my database


SELECT MSysObjects.Name

FROM MSysObjects

WHERE MSysObjects.Name NOT LIKE "~*" AND
MSysObjects.Type = 5;

You just need to add a sort to the name so:
Code:
SELECT MSysObjects.Name
FROM MSysObjects
WHERE (((MSysObjects.Name) Not Like "~*") AND ((MSysObjects.Type)=5))
ORDER BY MSysObjects.Name;
 
Thanks

Bob, I apologize for what are probably simple problems.......but your help is greatly appreciated. while you still may be there.....i asked another question in another section but i still havent figured it out....how can I limit the results of a parameter query to only show the latest record by date?
 
If in the QBE Grid (Query by example grid - what opens when you select a new query or edit an existing one), use a grouping query and select MAX for the Totals under the date field.
 

Users who are viewing this thread

Back
Top Bottom