How complex can you get with the SQL ORDER BY clause?
In the QBE, you can only put Ascending or Descending in the Sort cell for a field. But my query is too large for QBE and I have to use SQL. It's working fine, but now I want to add an ORDER BY clause. It needs to be conditional based on a selection from my parameter form - optSortBy.
So I coded as follows:
ORDER BY switch([forms]![formname]!.optSortBy=1,[Field1],[forms]![formname]!.optSortBy=2,[Field2],[forms]![formname]!.optSortBy=3,[Field3]);
There must be something wrong, because the form won't even save the code. When I take the code out the form saves and runs fine. When the code goes in, the form will not save and even kicks me out of Access.
In the QBE, you can only put Ascending or Descending in the Sort cell for a field. But my query is too large for QBE and I have to use SQL. It's working fine, but now I want to add an ORDER BY clause. It needs to be conditional based on a selection from my parameter form - optSortBy.
So I coded as follows:
ORDER BY switch([forms]![formname]!.optSortBy=1,[Field1],[forms]![formname]!.optSortBy=2,[Field2],[forms]![formname]!.optSortBy=3,[Field3]);
There must be something wrong, because the form won't even save the code. When I take the code out the form saves and runs fine. When the code goes in, the form will not save and even kicks me out of Access.