Question

I have a view with 2 level of category. How do I get the first and last entry of each of the second level category? The thing is I want to loop through each entry in the view and therefore I'm not using any GetAllEntriesByKey. If I'm using GetAllEntriesByKey then it's easier because from the resulting entries collection, I can just use it with GetFirstEntry and GetLastEntry. But the problem is I'm not using any key and I want to loop through the whole view. I've tried the following but I'm always getting 'Object Variable Not Set' at the line I commented and failed on first run. Never before I've encountered 'Object Variable Not Set' where the code is 'Loop'. Usually only on GetNextDocument if the previous document has been deleted.

Dim s As New NotesSession, db As NotesDatabase
Dim vw As NotesView, vec As NotesViewEntryCollection
Dim ve As NotesViewEntry, doc1 As NotesDocument, doc2 As NotesDocument
Set db = s.Currentdatabase
Set vw = db.Getview("View with 2 level category")
Set vec = vw.Allentries
Set ve = vec.Getfirstentry()
Do While ve.Document.Universalid <> vec.Getlastentry().Document.Universalid
    Do
        Set ve = vec.Getnextentry(ve)
    Loop Until ve.Iscategory = False 
    Set doc1 = ve.Document
    Do While ve.Iscategory = False 
        Set ve = vec.Getnextentry(ve)
    Loop 'always get object variable not set here
    Set doc2 = ve.Document
    Print doc1.UserDepartment(0)
    Print doc2.UserDepartment(0)
    Set ve = vec.Getnextentry(ve)
Loop
  • to avoid misunderstanding, the 2 level category which I meant is a view which the 1st and 2nd column is categorized
Was it helpful?

Solution

I do not understand at all, what you want to achieve... But:

Use the NotesViewNavigator Class to cycle through everything.

Dim ses as New NotesSession
Dim db as NotesDatabase
Dim viw as NotesView
Dim viwNav as NotesViewNavigator
Dim veCat as NotesViewEntry
Dim veCatNext as NotesViewEntry
Dim veDoc as NotesViewEntry
Set db = ses.CurrentDatabase
Set viw = db.Getview("View with 2 level category")
Set viwNav = viw.CreateViewNav
Set veCat = viwNav.GetFirst()
While not veCat is Nothing
  Set veCatNext = viwNav.GetNextCategory()
  If veCatNext.IndentLevel < veCat.IndentLevel '- This is a subcategory of the given category
    '- do whatever you want
    '- e.g. build a new viewnavigator from this using viw.CreateViewNavFromChildren
    '- or get the first document by set veDoc = viwNav.getNextDocument( veCat )
  Elseif  veCatNext.IndentLevel = veCat.IndentLevel '- This is the same (sub)category

  Else '- we are back to the next main category
  End If
  Set veCat = veCatNext
Wend
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top