Working with ASP is not as simple as working in MS Access. ASP bascially makes a one time run to spew out the HTML to the browser. If you want something different (such as a different sort) you must rerun the ASP with the necessary changes to do the something different.
To re-sort, you must run another SQL query with the desired ORDER BY statement. With 14 sorting fields, this results in a horrendous number of ORDER BY possibilities.
Here's some ideas off the top of my head
I suggest you try to limit the number of choices that can be made - not the number of fields, necessarily, just the number of fields that can be chosen. For example, if you limited the sort to 3 fields, you could have three dropdown fields on a form with the 14 field names as the options for the fields. But, if all 14 fields are demanded, then you'll need at least 13 dropdown fields.
The 2nd page (SQL page) will have to interpret the form submission values to build the ORDER BY portion of the SQL. If you construct the first page so the submitted values are the precise names of the table fields, then you could do something like...
Code:
sFld1 = request.form("D1")
sFld2 = request.form("D2")
sFld3 = request.form("D3")
' need one for each field on first page
SQLstring = "select * from tblWhatever"
' this would be the unsorted SQL for the data to be viewed
If len(trim(sFld1)) > 0 then
' check to see if the 1st sort field has data
SQLstring = SQL string & " Order By "
SQLstring = SQLstring & sFld1
If len(trim(sFld2)) > 0 then
' check to see if the 2nd sort field has data
SQLstring = SQLstring & "," & sFld2
end if
If len(trim(sFld3)) > 0 then
' check to see if the 3rd sort field has data
SQLstring = SQLstring & "," & sFld3
end if
' continue for as many sort fields as first page has
end if
' proceed on with connection and recordset opening
Unless you come up with some method on the first page, you might need to trap duplicate field selections such as a case where the user selects the same field name more than once. This could be done with the Instr() function - if the field names do not contain the name of another field (like RegionMgr and Region, for example) and this would not work if the SELECT statement names each field instead of using the asterisk (*).
Code:
If len(trim(sFld2)) > 0 then
' check to see if the 1st sort field has data
SQLstring = SQL string & " Order By "
SQLstring = SQLstring & sFld1
If len(trim(sFld2)) > 0 then
' check to see if the 2nd sort field has data
If Instr(1,SQLstring,sFld2) = 0 then
' check to see if field is already in SQL
SQLstring = SQLstring & "," & sFld2
End If
end if
If len(trim(sFld3)) > 0 then
' check to see if the 3rd sort field has data
If Instr(1,SQLstring,sFld3) = 0 then
SQLstring = SQLstring & "," & sFld3
End If
end if
' continue for as many sort fields as first page has
end if
I have not addressed ascending and descending sorting. If this is desired, it could be included in the options list of each dropdown field ("SalesRegion" & "Sales Region Desc"). This would double the choices on each list and might make the Instr() duplicate choice function more tricky.
These are just ideas. I haven't tried to make this code work because I'm too lazy and besides, that's your job.