combo box in alphabetical order

fabiobarreto10

Registered User.
Local time
Yesterday, 20:03
Joined
Dec 28, 2011
Messages
45
Gentlemen, I have a form with three combo boxes where one filters out the other. I'm trying to put them in alphabetical order
And the ORDER BY is not working.

I tried a few:

'Me.combEmpresa.RowSource = "SELECT CodEmpresa, NomeDaEmpresa FROM TblEmpresa WHERE CodAnalista= " & Forms!ffiltros!combAnalista & ";" AND ORDER BY TblEmpresa.NomeDaEmpresa
'Me.combEmpresa.RowSource = "SELECT CodEmpresa, NomeDaEmpresa FROM TblEmpresa WHERE CodAnalista= ORDER BY TblEmpresa.NomeDaEmpresa" & Forms!ffiltros!combAnalista & ";"
Me.combEmpresa.RowSource = "SELECT CodEmpresa, NomeDaEmpresa FROM TblEmpresa WHERE CodAnalista= " & Forms!ffiltros!combAnalista & "; ORDER BY TblEmpresa.NomeDaEmpresa"
'Me.combEmpresa.RowSource = "SELECT CodEmpresa, NomeDaEmpresa FROM TblEmpresa WHERE CodAnalista= " & Forms!ffiltros!combAnalista & ";"

but is not working.

Thanks anyone who can help.
 
Try

Me.combEmpresa.RowSource = "SELECT CodEmpresa, NomeDaEmpresa FROM TblEmpresa WHERE CodAnalista= " & Forms!ffiltros!combAnalista & " ORDER BY TblEmpresa.NomeDaEmpresa"
 
A few things to note here;

1) The ORDER BY clause is not preceded by the AND operator (as in your first example).

2) The ORDER BY clause would need to be inside the string (in your first example it is outside the string).

3) The ORDER BY clause could not be used as part of the comparison in the WHERE clause (as in your second example).

1) Most importantly, the semi-colon is a query terminator, so anything after the semi-colon would not be part of the query (as in your first and third examples).

Try this;

Code:
Dim strSQL As String

strSQL = "SELECT CodEmpresa, NomeDaEmpresa FROM TblEmpresa WHERE CodAnalista= " _
& Forms!ffiltros!combAnalista & " ORDER BY TblEmpresa.NomeDaEmpresa;"

Me.combEmpresa.RowSource = strSQL
 
pbaldy and Beetle, thanks for responding and helping.
Beetle thanks for the tips, It worked perfectly.

Thank you.
 
Happy to help.
 

Users who are viewing this thread

Back
Top Bottom