Sorting the results of a query

E

Ed Richter

I have a form that depending on criteria selected, displays certain records in a table. Everything was working fine. However, I'd like to add a field to the form to allow a user to select a criteria from that field to have the results sorted by. For example the person may want to sort by last name, phone number, etc. What I tried to do was replace the part of the "standard" query that it would specify what field to sort by, originally for example: ORDER BY L_name ASC and replace that with a variable called sort_order: ORDER BY '" & sort_order & "' ASC where sort_order was the field on the form.

The results being returned are not correct and I'm guessing that it doesn't appear that I've formatted the statement correctly to do this?? How can I utilize a variable sort order?
 
S

Stefan B Rusynko

If using the DBRW See http://home.att.net/~codelibrary/FrontPage/drwsort.htm
Otherwise your sql string had 1 extra set of quotes in it
strSQL = "Select * From Tablename ORDER BY " & sort_order & " ASC

--

_____________________________________________
SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
"Warning - Using the F1 Key will not break anything!" (-;
To find the best Newsgroup for FrontPage support see:
http://www.frontpagemvps.com/FrontPageNewsGroups/tabid/53/Default.aspx
_____________________________________________


I have a form that depending on criteria selected, displays certain records in a table. Everything was working fine. However, I'd
like to add a field to the form to allow a user to select a criteria from that field to have the results sorted by. For example the
person may want to sort by last name, phone number, etc. What I tried to do was replace the part of the "standard" query that it
would specify what field to sort by, originally for example: ORDER BY L_name ASC and replace that with a variable called
sort_order: ORDER BY '" & sort_order & "' ASC where sort_order was the field on the form.

The results being returned are not correct and I'm guessing that it doesn't appear that I've formatted the statement correctly to
do this?? How can I utilize a variable sort order?
 

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