why not pass the column to sort on into the COM object, and include it the SQL as an ORDER BY clause.
I've done this many times without data type specific errors.
Whats the error by the way...?
Sicknote
Main Topics
Browse All TopicsI am woking on an application where I am sorting the recordset based on the user input.
Currently I receive the recordset from a COM object and I am using:
rs.Sort = request("column_name")
It works fine when the column is of type Number or Date. But if the column is of a character type, then I get the following error. How do I fix this ?
Error Type:
Microsoft Cursor Engine (0x80040E60)
Sort order cannot be applied.
/results.asp, line 74
Thanks in advance.. (My first post..)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
sorry for the doublepost.
ticket is a column name and of long type. Its a default value for sort order. it works fine. And the data I am getting in the character field is usual data like a company name OR currency code(USD, JPY, EUR). So I dont understand why this is causing trouble. Its not data (i am sure about it because another application is sorting the same data via a Stored proc but I dont have that choice)
As I said earlier, I am getting the sort results fine when I sort Non-Char fields . Ticket is a default column and is of Number type. That is working fine.
When the user clicks on a column like Currency (which has a value of "USD", "EUR" or "JPY", then the code will be:
rs.Sort = "Currency"
this is when I get the above error.
mgfranz,
>> Wait a minute... if the field is just containing a test string, why are you storing it as a CHAR? "USD, EUR and JPY" are just text strings. <<
Why not? Char is just a fixed length character field. What other data type would you suggest?
>>Are you able to run a SORT in the SQL Query Engine in SQL? I am not sure you can even sort by CHAR type... <<
Sure you can. Again why not?
Anthony
tilakv,
>>When the user clicks on a column like Currency (which has a value of "USD", "EUR" or "JPY", then the code will be:
rs.Sort = "Currency"<<
In order to use the Sort Property, aside from the fact the provider and recordset must suport it (check out the Supports method), you must set the Index first.
Try posting all the relevant code and it may be more obvious.
Anthony
I thought it is a simple question but obviously it isn't.
Adding [ ] to the sort is actually creating an error.
The code is as simple as I wrote above. Also IsNull is not the problem as it is always passing the value whether the field type is of CHAR or NUMBER. when the user clicks on a button in one frame, it passes value to the other frame where I am retrieving the recordset and adding filter based on the button value.
Although this doesn't answer the question as to why the sort property cannot be applied to columns of a certain datatype, have a look at:
http://msdn.microsoft.com/
In the page there is the comment:
"Note In many cases, it's faster to open a new Recordset object by using an SQL statement that includes the sorting criteria."
Is there a reason for wishing to specifically use the sort proerty?
Sicknote
There is a couple of reasons a sort would fail:
Firstly, your cursor needs to be a Client side cursor.
-- rs.CursorLocation = adUseClient
The sort Column may not be a reserved word - especially not ASC or DESC
If your column name contains spaces you need to put square brackets around it
-- [Last Name]
Double check the type - it may not be bit or binary or image, text, etc. - preferably varchar
Lastly: (Q189837) (MS Confirmed bug)
Symptom
-------
When you use an ADO recordset object, you cannot Sort on a field with more than 255 characters. Attempting to sort on a field with more that 255 characters results in the following error:
Run-time error '-2147217824 (80040e60)': The requested order could not be opened
You also see this error on attempting to sort on a SQL Server Text field, a Microsoft Access Memo field, or other Binary Large Object (BLOB) field.
With ADO 2.1 Service Pack 2 and later, this error does not occur on attempting to sort on a field with more than 255 characters. However, this error does occur on attempting to sort on a Binary Large Object (BLOB) field.
Upgrade to ADO 2.6 or later (Microsoft download - ms data access components)
Should help
Louis
sicknote,
I am receiveing the recordset from a com object which is used by other apps too. so, i cant ask them to change it for me.. u know.. too much headache going around for it.
Louis,
the cursor is a a client side cursor. and the column is not a reserved word either as mentioned earlier.
its a varchar type and the values are less than 30 char.
Its not working on 3 chars either..for example Currency codes USD, EUR..
i am going nuts trying to figure this out. the database is Sybase.
If it is any consolation, a search on Google for "Sort order cannot be applied." proves your not the only one with this problem:
http://textcontrol.com/tx/
I do not believe the solution suggested is correct.
Anthony
Hi everybody,
I think I figured out why it is not working. Actually, the recordset was created by Appending fields to it and the columns were defined as the data type "adBSTR". I requested to change the data type to "adVARCHAR" in the DLL and it worked like a charm.
Sorry if I have misled any of you but it was completely unintentional. I was under the impression too that the data type was varchar as per what I was told.
Now I need to find out how to lock this thread.
sorry.. I was told by the people working on COm object that it was character type. when i went to double check, i found this out. But this forum sure helped as it led me to the suspicion on data type.
thanks everybody.. i will accept Louis's answer..
i have no idea what these point mean though.. havent read the rules properly yet. trying to find out..
Business Accounts
Answer for Membership
by: jitgangulyPosted on 2002-10-18 at 09:33:08ID: 7345256
>>I get the following error
What error ?