Reputation: 1931
I am trying to find the count of entries in a Domino database using a lotus-script based on a certain column. I have created the following script below which runs okay but the message box total is a few hundred less than the total in the dialogue presented at the close of the script. I am assuming one is including all the parent categories etc. How do I count the number of records in the view based on the "Date Created" column?
I have included an image of the column I want a total for in the view.
Sub Initialize
Dim db As NotesDatabase
Dim view As NotesView
Dim s As NotesSession
Dim NotesDocColl As NotesDocumentCollection
Dim requestDoc As NotesDocument
Dim lngDocCount As Long
Set s = New NotesSession
Set db = s.CurrentDatabase
Set view = db.GetView("By Category")
Set requestDoc = view.Getfirstdocument()
lngDocCount = 0
Do Until requestDoc Is Nothing
lngDocCount = lngDocCount + 1
Set requestDoc = view.GetNextDocument(requestDoc)
Loop
MessageBox "Number of documents = " & lngDocCount
End Sub
Upvotes: 1
Views: 1427
Reputation: 67
What you want is a NotesViewNavigator object. This powerful tool allows you to leverage the work your view is doing for you generating totals, counts, calculated column values, etc, without the overhead of having to instantiate each document object. For your example try this snippet:
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim nv As NotesViewNavigator
Dim e As NotesViewEntry
Dim dc As NotesDocumentCollection
Set db = session.Currentdatabase
Set view = db.getview("Categories")
Set nv = view.Createviewnav()
Set e = nv.Getfirst()
Dim categcount, totalcount
While Not e Is Nothing
If e.Indentlevel=3 Then
categcount = e.Childcount '<-do something with this value
totalcount = totalcount+categcount
End If
Set e = nv.Getnext(e)
Wend
End Sub
Check out all the properties of a NoteviewEntry class. You may find some other useful things like .Siblings
Upvotes: 2
Reputation: 1632
The following code will get you the "total documents created for ALL the 98 categories in the view":
Dim db As NotesDatabase
Dim view As NotesView
Dim s As NotesSession
Dim NotesDocColl As NotesDocumentCollection
Set s = New NotesSession
Set db = s.CurrentDatabase
Set view = db.GetView("By Category")
Set NotesDocColl = db.Search(view.Selectionformula, Nothing, 0)
MessageBox "Number of documents = " & NotesDocColl.Count
To get the number of docs for each category, I add a column to the view that computes to 1, and is totaled (bottom of the sort tab in designer) with "Hide detail rows" selected. Most times it is the first column in the view.
To get it programatically I use a NotesViewNavigator and iterate through the top level categories.
Upvotes: 0