Sorting a combo box populated by code

S

Sam

I have an unbound combo box on a form that I want to sort
alpha...

The combo box gets its values On Load like this:

If Len(Form.Filter) > 0 Then
cboFindContact.RowSource = "SELECT [Contacts].
[CustomerID], [Contacts].[CompanyName] FROM [Contacts]
WHERE " & Form.Filter

The bound column is 1, but I would like to sort the values
in Col 2.

I've found a few examples of sorting a list box using a
Sub and using a function to sort an Array, but I can't get
anything to work.

Any help would be appreciated!

Thanks,
Sam
 
G

Glen Appleton

Hi Sam,

Try adding the Order By directive to the SQL statement in the Row Source
property. For example:

cboFindContact.RowSource = "SELECT [Contacts].[CustomerID],
[Contacts].[CompanyName] FROM [Contacts] WHERE " & Form.Filter & " ORDER BY
[Contacts].[CompanyName]"

Hope this helps,
- Glen
 
S

Sam

Glen,

Thank you very much, that did the trick.

Much appreciated,
Sam
-----Original Message-----
Hi Sam,

Try adding the Order By directive to the SQL statement in the Row Source
property. For example:

cboFindContact.RowSource = "SELECT [Contacts]. [CustomerID],
[Contacts].[CompanyName] FROM [Contacts] WHERE " & Form.Filter & " ORDER BY
[Contacts].[CompanyName]"

Hope this helps,
- Glen


Sam said:
I have an unbound combo box on a form that I want to sort
alpha...

The combo box gets its values On Load like this:

If Len(Form.Filter) > 0 Then
cboFindContact.RowSource = "SELECT [Contacts].
[CustomerID], [Contacts].[CompanyName] FROM [Contacts]
WHERE " & Form.Filter

The bound column is 1, but I would like to sort the values
in Col 2.

I've found a few examples of sorting a list box using a
Sub and using a function to sort an Array, but I can't get
anything to work.

Any help would be appreciated!

Thanks,
Sam


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top