- The GetDocumentByKey method finds the first document in the view that matches "Blowfish."
- To find subsequent matching documents, the script loops through the remaining documents in the view. It keeps looping as long as the document matches the key. To match the key, the document's column value for the first sorted and categorized column in the view must equal "Blowfish."
Why doesn't the script look for documents where doc.ColumnValues(0) = "Blowfish"? Because the first column in the view may or may not be the first sorted and categorized column in the view. Therefore, the script uses the IsSorted property to find the first sorted and categorized column in the view and uses column.Position - 1 to get the correct column value from the document.
Sub Initialize
Dim db As New NotesDatabase( "", "ocean.nsf" )
Dim view As NotesView
Dim column As NotesViewColumn
Dim doc As NotesDocument
Dim done As Variant
Set view = db.GetView( "By Category" )
' get the first sorted and categorized column in the view
Forall c In view.Columns
If ( c.IsSorted And c.IsCategory ) Then
Set column = c
Exit Forall
End If
End Forall
' get the first document that matches the key
Set doc = view.GetDocumentByKey( "Blowfish" )
' get the remaining documents that match the key
' since ColumnValues array starts at 0 for position 1,
' subtract 1 from the column position
While ( doc.ColumnValues( column.Position - 1 ) _
= "Blowfish" )
Call doc.PutInFolder( "Fishy" )
Set doc = view.GetNextDocument( doc )
Wend
End Sub