Lotus Notes FAQ Visit Our Sponsor!

How do you go to the last document in a category using Lotuscript?

You can also use the routine below to move onto the next category by moving to the last document in a specified category, then using view.GetNextDocument to move to the next category. Call the routine below as follows:
notesBackendDoc = GoToLastDocInCategory(StartDoc, View, FieldName, CategoryValue)

- a NotesDocument in the category that you want to start out the search from.
- a NotesView that you will be searching.
- a String containing the name of the item that holds the Category value.
- a String containing what category value to check for.

Function GoToLastDocInCategory(StartDoc As NotesDocument, CheckView As
NotesView, ItemName As String, CategoryValue As String) As NotesDocument
  Dim PreviousDoc As NotesDocument
  Dim NextDoc As NotesDocument
  Dim CategoryItem As NotesItem
  Dim ThisDocCategoryValue As String
  Set NextDoc = StartDoc
  Set PreviousDoc = StartDoc
  Set CategoryItem = StartDoc.GetFirstItem(ItemName)
  ThisDocCategoryValue = CategoryItem.Text
  Do While Not(NextDoc Is Nothing) And (CategoryValue = ThisDocCategoryValue)
    Set PreviousDoc = NextDoc
    Set NextDoc = CheckView.GetNextDocument(NextDoc)
    If NextDoc Is Nothing Then Exit Do
    Set CategoryItem = NextDoc.GetFirstItem(ItemName)
    ThisDocCategoryValue = CategoryItem.Text
  Set GoToLastDocInCategory = PreviousDoc
End Function

Applies to Notes Versions: 4 4.5 4.6 5
Last Modified: January 23, 1997