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
Solved

Sorting a dynamically created recordset

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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.
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…
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…

808 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