ORDER BY not working

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
 
J

john.fuller

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...."
 
J

jutlaux

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.
 

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