2017-05-26 62 views
1

我正在嘗試使用基於特定列的蓮花腳本來查找Domino數據庫中條目的計數。我創建了下面的腳本,其運行正常,但消息框總數比腳本結束時提供的對話總數少了幾百。我假設一個是包括所有父類別等。如何根據「創建日期」列來計算視圖中的記錄數?按列數計算文檔

我在視圖中包含了我想要的總計列的圖像。

enter image description here

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 
+0

每個文檔是否只出現在一個類別中?我的猜測是,事實並非如此。 –

+0

你想知道什麼?視圖中選擇了多少個文檔或視圖中有多少文檔創建了特定的日期?您是否無法根據創建的日期創建可以遍歷的替代視圖? – Newbs

+0

@RichardSchwartz我對遲到的反饋表示歉意,但昨天這裏是蘇格蘭的公衆假期。每個創建的文檔都不是唯一的。謝謝 – AJF

回答

0

下面的代碼,會得到「所有98個大類在視圖中創建的總文件」:

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 

要獲取文檔的數量爲每個類別,我向計算爲1的視圖添加一列,並且在選擇「隱藏詳細信息行」的情況下進行總計(設計器中排序選項卡的底部)。大多數時候這是視圖中的第一列。

爲了獲得它,我使用NotesViewNavigator並遍歷頂級類別。

+0

我在上面給你添加了一條評論 – AJF

2

你想要的是一個NotesViewNavigator對象。這個強大的工具允許您利用視圖爲您生成總計,計數,計算列值等的工作,而無需實例化每個文檔對象的開銷。對於你的例子試試這個片段:

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 

檢查出NoteviewEntry類的所有屬性。您可能會發現一些其他有用的東西。兄弟姐妹