Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADODB sort Error

Status
Not open for further replies.

TimRHSD

Programmer
Apr 18, 2002
35
0
0
US
Hi,

When I try adding a sort to my adodb, I am getting an error, 'Wrong number of arguments or invalid property assignment'. I have checked all over for examples and can't seem to resolve this. The error occurs with the sort. Will someone point out what I am doing incorrectly?

Thanks,
Tim

Code:
set rst = CreateObject("ADODB.recordset")
rst.CursorLocation = adUseClient
rst.Fields.Append "Dept", adChar,4
rst.Fields.Append "Location", adChar,3
rst.Fields.Append "Fund", adChar,3
rst.Fields.Append "EmpID", adChar,7
rst.Fields.Append "EmpName", adChar,30
rst.Fields.Append "Date", adDate
rst.Fields.Append "Hours", adDecimal
rst.Fields.Append "HourNumber", adChar,4
rst.Fields.Append "GLKey", adChar,10
rst.Fields.Append "GlObj", adChar,10
rst.Fields.Append "NumberOfHours", adDecimal
rst.Open
rst.Sort "Fund,Dept,Location,Globj,EmpName"
'Tried using the following as well and it didn't work either
'rst.Sort "Fund Asc,Dept Asc,Location Asc,Globj Asc,EmpName Asc"



Tim Rutherford
 
Are you sure this line isn't the problem:
rst.Open
Doesn't .Open require a parameter?

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Tom,

When I comment out the 'Sort' line, the code works. However, as one would expect, not sorted. BTW, what parameters would I use with the Open statement. I am pretty new to adodb and don't recall seeing parameters for Open.

Thanks,
Tim

Tim Rutherford
 
I'm no ADODB pro either. :) I'll see what I can dig up, but in the meantime one of the smart people will probably have an answer.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Ok, I think I know what the problem is. All that the .Append is doing is essentially creating the fields in your recordset. When you use sort, there isn't any actual data to sort. Try adding some data to the recordset first then sorting.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Tom,
I found my problem. There needs to be an equal sign after 'Sort'.
rst.sort = "a, b, c"

I was using rst.sort "a, b, c" w/out the '='

Thanks for the ideas to check anyhow.

Tim

Tim Rutherford
 
Glad to here that even the blind leading the blind works out sometimes. Now I know a little more about ADO too.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Tom,
FYI, I found if you don't have the sort statement before you start loading data, it doesn't sort it (I am using a report writer which uses vbscript). You need to have .Sort right after the .Open statement.

Someone correct me if I am wrong.

Tim

Tim Rutherford
 
You can look at faq329-3362.

Or, when in doubt go to the source:
The Recordset does not have to be opened before accessing the Sort property; it can be set at any time after the Recordset object is instantiated.
Sort Property

As a matter of fact you can set Sort to one value, use the data, then change Sort to another criteria string and use it again in the new sequence.

Filter is another powerful Recordset property.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top