Sort a collection??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have created a collection as a staging area. I would like to sort the
collection. Is there a way to sort the collection>

Thank you,
 
You have to add items to the collection in the sort order you want. Here's
an example:

Add A New Date To The NewCourseSectionDates Collection In Sort Ascending
Order

Function AddCalendarDateToCollection()

Dim DateSelected As Date

DateSelected = DateSerial(Forms!FrmCalendarMonth!CalYear,
Forms!FrmCalendarMonth!CalMonthNum, Screen.ActiveControl.Value)

' Check If The Selected Date Was Previously Selected

If NewCourseSectionDates.Count > 0 Then

For Each NewCourseSectionDate In NewCourseSectionDates

If NewCourseSectionDate = DateSelected Then

msgbox DateSelected & " Has Already " _

& "Been Selected As A Course Section Date", , "Duplicate Date"

Forms!FrmCalendarMonth!TextBoxForFocus.SetFocus

Exit Function

End If

Next

End If

' Add The Selected Date To The Collection Before The First Date Already In
The Collection

' That Is Greater Than The Selected Date. This Keeps The Dates In The
Collection

' Sorted chronologically

Dim I As Integer

If NewCourseSectionDates.Count > 0 Then

For I = 1 To NewCourseSectionDates.Count

If DateSelected < NewCourseSectionDates(I) Then

NewCourseSectionDates.Add DateSelected, , I

Exit Function

End If

Next I

End If

NewCourseSectionDates.Add DateSelected

End Function
 
Back
Top