ADO Stream Object sorts the field order - why?

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,907
Office Version
  1. 365
Platform
  1. Windows
Hi All

A little while back Andrew showed me that using the ADO Stream object I could preserve the recordset filter. I am using this:

Code:
Public Function FilterRecordSet(ByVal objRecordSet As ADODB.RecordSet, ByVal strFilterText As String) As ADODB.RecordSet
    Dim objStream As ADODB.Stream
    
    On Error Resume Next
        objRecordSet.Filter = strFilterText
    On Error GoTo 0
    
    Set objStream = New ADODB.Stream
    With objRecordSet
        .Save objStream, adPersistXML
        .Close
        .Open objStream
    End With
    
    Set FilterRecordSet = objRecordSet
End Function

This seems to order the fields alphabetically. Do you know how to avoid this, or do you know an alternative way to use the filter method on a recordset and dump the filtered results (without looping through all records)?
 
Thanks Rory. I really appreciate it. This isn't a show stopper but unless I can get to the bottom of it, it will cause me a bit of rework...
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Just sent you an email. If you change the cursorlocation of the recordset to use a client side cursor, then the problem is averted.
 
Upvote 0
Sweet! :biggrin: What made you think of that?

Edit: I'm moving this to public forum. I don't think this topic has been covered before so I imagine it may help someone some day. I only posted in MVP forum because I knew Rory would get to it this way. :biggrin:
 
Upvote 0
It was the only obvious difference I could see between what you were doing and what I had done. Still not really sure why that should make a difference and I didn't actually test the saved output to see if that was in alphabetical order, or if it was reloading it that made the change.
 
Upvote 0
The outputs are perfect now. :) I don't either get why it should make ablind bit of difference but for now I don't care; just happy that it works. I've already moved onto my next snag (stupid string field contains mix of #'s and text and throws mismatch when converting to array). Grrr! Anyway I think I have work-around for this.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top