Combo Box Sorting

N

Neil

Hi,
I am using the following code in the after update event of a combo box
[cboregion] to sync another combo box [Combo5], it all works except when the
first "if" is true it doesn't sort the salesman. I have tried putting the
ORDER BY[Salesman] in but cannot get it to work.

I am stumped on how to sort by salesman and help would be appreciated

Dim sSource As String
If Me.cboRegion.Value <> 10 Then
sSource = "SELECT [tblsalesman].[ID], [tblsalesman].[region],
[tblsalesman].[salesman] " & _
"FROM tblSalesman " & _
"WHERE [region] = " & Me.cboRegion.Value
Me.Combo5.RowSource = sSource
Else
Me.Combo5.RowSource = "SELECT [tblsalesman].[ID],
[tblsalesman].[Region], [tblsalesman].[salesman] FROM tblSalesman ORDER BY
[Salesman]"
End If
Me.Combo5.Requery


thanks in advance
Neil
 
D

Duane Hookom

How about
Dim sSource As String
If Me.cboRegion.Value <> 10 Then
sSource = "SELECT [ID], [region], [salesman] " & _
"FROM tblSalesman " & _
"WHERE [region] = " & Me.cboRegion.Value
Else
sSource = "SELECT [ID], [Region], [salesman] " & _
"FROM tblSalesman "
End If
Me.Combo5.RowSource = sSource & " ORDER BY Salesman"
 
N

Neil

Thanks very much, works a treat.

Neil

Duane Hookom said:
How about
Dim sSource As String
If Me.cboRegion.Value <> 10 Then
sSource = "SELECT [ID], [region], [salesman] " & _
"FROM tblSalesman " & _
"WHERE [region] = " & Me.cboRegion.Value
Else
sSource = "SELECT [ID], [Region], [salesman] " & _
"FROM tblSalesman "
End If
Me.Combo5.RowSource = sSource & " ORDER BY Salesman"


--
Duane Hookom
MS Access MVP


Neil said:
Hi,
I am using the following code in the after update event of a combo box
[cboregion] to sync another combo box [Combo5], it all works except when
the first "if" is true it doesn't sort the salesman. I have tried putting
the ORDER BY[Salesman] in but cannot get it to work.

I am stumped on how to sort by salesman and help would be appreciated

Dim sSource As String
If Me.cboRegion.Value <> 10 Then
sSource = "SELECT [tblsalesman].[ID], [tblsalesman].[region],
[tblsalesman].[salesman] " & _
"FROM tblSalesman " & _
"WHERE [region] = " & Me.cboRegion.Value
Me.Combo5.RowSource = sSource
Else
Me.Combo5.RowSource = "SELECT [tblsalesman].[ID],
[tblsalesman].[Region], [tblsalesman].[salesman] FROM tblSalesman ORDER
BY [Salesman]"
End If
Me.Combo5.Requery


thanks in advance
Neil
 

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