so let's say the record source for your form is "SELECT * FROM tblTest" Let's also say on your form you have a button named cmdResort.
Let's say on tblTest you have three fields Field1, Field2, Field3
You want to be able to sort by any of those three fields in any order you want.
you would have to have a combo box or some other mechanism to say which FIELD you wanted to sort by first and whether you wanted it to be descending or ascending
so let's call these 6 controls
Sort1 SortType1
Sort2 SortType2
Sort3 SortType3
where sort 1 through 3 are your combo boxes with field names, your sorttype 1 through 3 is your ascending or descending
You'd have to have code something like this attached to your cmdResort:
Code:
dim sSQL as string
sSQL = "SELECT * FROM tblTEST"
if not isnull(sort1) then
sSQL = & " ORDER BY [" & sort1 & "]"
if sorttype1 = "DESCENDING" then
sSQL = sSQL & " DESC"
endif
endif
if not isnull(sort2) then
sSQL = & ", [" & sort2 & "]"
if sorttype2 = "DESCENDING" then
sSQL = sSQL & " DESC"
endif
endif
if not isnull(sort3) then
sSQL = & ", [" & sort3 & "]"
if sorttype3 = "DESCENDING" then
sSQL = sSQL & " DESC"
endif
endif
me.rowsource = ssql
me.requery
NOTE I didn't test this query but basically what you're doing is changing the rowsource of the form to be a new query with a new sort order and you're building the SQL statement that you can base it on. This also assumes that if you have a sort 3 you will have a sort 2 AND a sort 1, in other words you're preventing someone from having 'gaps' in the sorts.