OpenNTF.org - Function to sort a collection
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
Function to sort a collection the same way as a view 
Rating:
Rating: 4 , Number of votes: 1 
Contributor:
Benoit Dubuc 
Category:
Lotusscript 
Type:
Miscellaneous 
Notes Version:
R5.x, R6.x 
Last Modified:
19 Nov 2003 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
Function SortDocumentCollection (coll As NotesDocumentCollection, ViewName As String) As NotesDocumentCollection

'This function takes a NotesdocumentCollection and sorts in the same order as the specified view.
'It actually creates a new collection by navigating through the view and adding documents
'as it encounter them in the NotesViewEntryCollection
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim entry As NotesViewEntry
Dim vc As NotesViewEntryCollection
Dim SortedColl As NotesDocumentCollection
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set view = db.GetView(ViewName)
Set vc = view.AllEntries
'initialise the new collection - trick is to create an empty collection because the collection needs to be initialized before we can add documents into it
Set SortedColl = view.GetAllDocumentsByKey("zzxxzz")
'scan AllEntries
Set entry = vc.GetFirstEntry
While Not entry Is Nothing
'get a document from AllEntries and add it to the new collection
Set doc = coll.GetDocument(entry.Document)
Call SortedColl.AddDocument(doc)
Set entry = vc.GetNextEntry(entry)
Wend
'return the new collection
Set SortDocumentCollection = SortedColl
End Function

Usage / Example
dim myColl as NotesDocumentCollection
...
set myColl = aView.Alldocuments
myColl = SortDocumentCollection( myColl, "AnotherView")
 Comments
Posted by Beau Green on 12/11/2003 04:15:46 PMAdditions
"view" will always be in the same database as the "coll" NotesDocumentCollection. Here's is an altername way to set "view".
Set view = coll.Parent.GetView(ViewName)
"doc" should also be checked before adding it to the new collection.
If Not( doc Is Nothing ) Then
If Not( doc.IsDeleted ) Then
Call SortedColl.AddDocument(doc)
End If
End If
 Add your comment!