Solved

Sorting a dynamically created recordset

Posted on 2004-09-01
4
300 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:winterhowl
4 Comments
 
LVL 9

Expert Comment

by:samopal
ID: 11957834
1)Dynamically created recordsets does not suppor SORT method.

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
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 100 total points
ID: 11959561
The Sort method can be used on ALL recordsets.

Simply replace adBSTR by adVarChar
0
 

Author Comment

by:winterhowl
ID: 11960323
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!  :)
0
 
LVL 10

Expert Comment

by:anv
ID: 11960329
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.)
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question