Change Sort Order Of A Query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey all,

If I have a saved query in Access 2000, is there any way I can
programatically change which columns it is sorted on? Based on user criteria,
there are cetain columns I may want to turn "on" or "off" in terms of the
sort.

Preferably, I'd like to do this on a temporary basis (only for as long as
it takes to create a DAO recordset), without changing the actual query.
 
If you only want to apply the sorting on a DAO recordset then it's a pice of
cake! Assuming the saved query is called MyQuery, then instead of:

Set rst = CurrentDb.OpenRecordset(MyQuery)

You can:

strSQL = "SELECT * FROM MyQuery ORDER BY " & UserChoiceOfField
Set rst = CurrentDb.OpenRecordset(strSQL)

Where UserChoiceOfField is a variable holding the name of the field the user
has opted to sort on. It can be easily adapted to sort on several fields.

HTH,
Nikos
 
Back
Top