winterhowl
asked on
Sorting a dynamically created recordset
I'm trying to sort a dynamically created recordset, but I can't get to the code to work.
Here's what I'm working with:
Set rsWorkFile = New Recordset
rsWorkFile.Fields.Append "SortKey", adBSTR, 41
rsWorkFile.Fields.Append "Keywords", adBSTR, 959
Open strInputFile For Input As #1
Open strOutputFile For Output As #2
rsWorkFile.Open
Do While Not EOF(1)
Line Input #1, strInputRec
rsWorkFile.AddNew
rsWorkFile!SortKey = Mid(strInputRec, 1, 41)
rsWorkFile!Keywords = Mid(strInputRec, 42, 958)
rsWorkFile.Update
Loop
rsWorkFile.MoveFirst
' An error on this line says "Sort Order Cannot Be Applied"
rsWorkFile.Sort = "SortKey"
Do While Not rsWorkFile.EOF
strOutputRec = rsWorkFile!SortKey & rsWorkFile!Keywords
Print #2, strOutputRec
rsWorkFile.MoveNext
Loop
Close #1
Close #2
Here's what I'm working with:
Set rsWorkFile = New Recordset
rsWorkFile.Fields.Append "SortKey", adBSTR, 41
rsWorkFile.Fields.Append "Keywords", adBSTR, 959
Open strInputFile For Input As #1
Open strOutputFile For Output As #2
rsWorkFile.Open
Do While Not EOF(1)
Line Input #1, strInputRec
rsWorkFile.AddNew
rsWorkFile!SortKey = Mid(strInputRec, 1, 41)
rsWorkFile!Keywords = Mid(strInputRec, 42, 958)
rsWorkFile.Update
Loop
rsWorkFile.MoveFirst
' An error on this line says "Sort Order Cannot Be Applied"
rsWorkFile.Sort = "SortKey"
Do While Not rsWorkFile.EOF
strOutputRec = rsWorkFile!SortKey & rsWorkFile!Keywords
Print #2, strOutputRec
rsWorkFile.MoveNext
Loop
Close #1
Close #2
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I figured that out shortly after I posted this question, except I just used adChar. I didn't use that at first, because I had C++ on the brain.
Thank you both for the help! :)
Thank you both for the help! :)
try doing this
set the recordsets CursorLocation to client (i think, else change to server)
then try to use the sort method
(actually in one of my project i did this and i dont remember whether i change d it to client or server, then i used the order by query in it, may be sort will be supported that ways.)
set the recordsets CursorLocation to client (i think, else change to server)
then try to use the sort method
(actually in one of my project i did this and i dont remember whether i change d it to client or server, then i used the order by query in it, may be sort will be supported that ways.)
2)To sort a text file you don't need to create dynamic recordset, there are more simple ways to do this.
Fo example, you can do this using DOS sort command :
Shell "cmd /c sort " strInputFile & " /o " & strOutputFile
Hope This Helps,
D'Al