Solved

Sorting a dynamically created recordset

Posted on 2004-09-01
4
296 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 69

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now