ORDER BY not working

  • Thread starter Thread starter jutlaux
  • Start date Start date
J

jutlaux

I am using cascading combo boxes and have a SELECT statement in one of them
that I now want to add and ORDER BY statement to. When I added the ORDER BY
part to the working SELECT statement it did not ORDER the data. The cascading
part still worked, just no order to the second combo box. What did I do
wrong or miss?

Some other notes cboEquipmentID is the first combo box that populates the
second combo box cboCurrentMachineNum


Private Sub cboEquipmentID_AfterUpdate()

cboCurrentMachineNum.RowSourceType = "Table/Query"
cboCurrentMachineNum.RowSource = _
"SELECT intMachineNumber from tblMachineNumber WHERE strMachineType
= """ & cboEquipmentID & """ ORDER BY strMachineType"

End Sub
 
I am using cascading combo boxes and have a SELECT statement in one of them
that I now want to add and ORDER BY statement to.  When I added the ORDER BY
part to the working SELECT statement it did not ORDER the data. The cascading
part still worked, just no order to the second combo box.  What did I do
wrong or miss?

Some other notes cboEquipmentID is the first combo box that populates the
second combo box cboCurrentMachineNum

Private Sub cboEquipmentID_AfterUpdate()

    cboCurrentMachineNum.RowSourceType = "Table/Query"
    cboCurrentMachineNum.RowSource = _
        "SELECT intMachineNumber from tblMachineNumber WHERE strMachineType
= """ & cboEquipmentID & """ ORDER BY strMachineType"

End Sub

Try "ORDER BY tblMachineNumber.strMachineType" and see if that works.
May not be necessary but I always write my queries specifying the
table all the time, ie i would write what you have as "SELECT
tblMachineNumber.intMachineNumber FROM tblMachineNumber WHERE
tblMachinNumber.strMachineType...."
 
The problem was that I was trying to ORDER BY a field that was not in the
combo box. strMachineType was a string used for the WHERE. Once I changed
the ORDER By to intMachineNumber it worked fine. Thanks for your help.
 
Back
Top