Solved

Sorting a dynamically created recordset

Posted on 2004-09-01
4
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

615 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