Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Posts
    311

    Unanswered: Sorting a Collection

    I have a collection i have added Num Vals to, in no specific order.

    I would like to sort the collection, how can i do that?

    M~

  2. #2
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile Re: Sorting a Collection

    Originally posted by mikezcg
    I have a collection i have added Num Vals to, in no specific order.

    I would like to sort the collection, how can i do that?

    M~
    I would perform whatever sorting you want before adding them to the collection. You can insert items before or after other items in a collection but to me it would be more cumbersome.

    Where are the values coming from? Are they from table fields?

    Just curious.

    Gregg


    Additional thoughts:

    You could try a recordset to sort.

    Like this:

    Dim col1 As New Collection
    Dim rs As ADODB.Recordset, x As Integer
    Set rs = New ADODB.Recordset

    For x = 1 To 10
    col1.Add x
    Next

    With rs
    .Fields.Append "Item", adInteger
    .Sort = "Item desc"
    .Open

    For x = 1 To col1.Count
    .AddNew
    .Fields(0) = col1(x)
    .Update
    Next

    .MoveFirst
    Do While Not .EOF
    MsgBox .Fields(0)
    .MoveNext
    Loop

    End With

    Set rs = Nothing

    Gregg
    Last edited by basicmek; 11-19-03 at 20:54.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •