This example shows how to sort a User Defined Type (UDT), but you can change it for use with any kind of data (not only UDTs).

This shows how to make a temporary unconnected table, where you insert data into, then you can sort by any field, and any combination, just like you do it in SQL.

You must add a reference to "Microsoft ActiveX Data Objects x.x Library" where "x.x" is your latest version that you have.

vb Code:
  1. Option Explicit
  2.  
  3. Private Type t_MyData
  4.     strField As String
  5.     intField As Long
  6.     dateField As Date
  7. End Type
  8.  
  9. Private ArrMyData(0 To 30) As t_MyData
  10.  
  11. Private Sub Form_Load()
  12.     Dim rsData As New ADODB.Recordset ' unconnected table (Add a reference to "Microsoft ActiveX Data Objects")
  13.     Dim K As Long
  14.    
  15.     Randomize
  16.    
  17.     ' put some random data into the array for testing
  18.     For K = LBound(ArrMyData) To UBound(ArrMyData)
  19.         ArrMyData(K).strField = Chr(65 + 3 * Rnd)
  20.         ArrMyData(K).intField = Fix(100 * Rnd)
  21.         ArrMyData(K).dateField = DateAdd("d", -K, Date)
  22.     Next K
  23.    
  24.     With rsData
  25.         ' create the fields that we are gonna sort
  26.         .Fields.Append "ArrIndex", adInteger
  27.         .Fields.Append "strField", adVarChar, 255
  28.         .Fields.Append "intField", adInteger
  29.         .Fields.Append "dateField", adDate
  30.        
  31.         .Open ' open the recordset so we can add our data
  32.        
  33.         ' add the data into the temporary unconnected table
  34.         For K = LBound(ArrMyData) To UBound(ArrMyData)
  35.             .AddNew
  36.            
  37.             .Fields("ArrIndex").Value = K
  38.             .Fields("strField").Value = ArrMyData(K).strField
  39.             .Fields("intField").Value = ArrMyData(K).intField
  40.             .Fields("dateField").Value = ArrMyData(K).dateField
  41.            
  42.             .Update
  43.         Next K
  44.        
  45.         ' do the sorting
  46.         .Sort = "[strField] DESC, [intField] ASC"
  47.        
  48.         ' display the result in the Immediate window (debug window)
  49.         .MoveFirst
  50.         Do Until rsData.BOF Or rsData.EOF
  51.             Debug.Print .Fields("ArrIndex").Value, .Fields("strField").Value, .Fields("intField").Value, .Fields("dateField").Value
  52.            
  53.             .MoveNext
  54.         Loop
  55.     End With
  56. End Sub