Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sorting a dynamically created recordset

Posted on 2004-09-01
4
Medium Priority
?
312 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 400 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Suggested Courses

772 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