2

TestView1 のドキュメントをループし、そのビューのドキュメントごとに TestView2 のドキュメントをループして、何らかのアクション (ファイルへの出力) を実行する次のコードがあります。

ループを比較的タイムリーに保つために (古いドキュメントがたくさんあり、今日または次の日付からのタイム スタンプのみが必要です)、現在の日付の最初のドキュメントを見つけ、その UNID を保存して、そのドキュメントができるようにしました。内部ループの開始位置として機能します (MyView2 のドキュメントは時系列順です)。

内側のループは最初は正しく実行されますが、2 回目のループでは、"The document is not in view TestView2" というエラー メッセージが表示されます。コードを分割する行を追加しました。

これが私のコードです:

Dim sess As New NotesSession
Dim db As NotesDatabase
Dim rDoc As NotesDocument
Dim mDoc As NotesDocument
Dim rView As NotesView
Dim mView As NotesView
Dim unid As String
Dim todayDateTime As New NotesDateTime("Today")

Set db = sess.currentDatabase
Set rView = db.GetView("TestView1")
Set rDoc = rView.GetFirstDocument
Set mView = db.GetView("TestView2")
Set mDoc = mView.GetFirstDocument

Set mDoc = mView.GetFirstDocumentb 'Finds the UNID of the first document of the day
Do While Not (mDoc Is Nothing)
    Dim startDate As New NotesDateTime(mDoc.startDate(0))
    If startDate.DateOnly = todayDateTime.DateOnly Then
        unid$ = mDoc.UniversalID
        Exit Do
    End If
    Set mDoc = mView.GetNextDocument(mDoc)
Loop

While Not (rDoc Is Nothing) 'Outer Loop
    If rDoc.Site(0) = "SAMPLE" Then

        <CODE>

        If Not unid$ = "" Then
            Set mDoc = db.Getdocumentbyunid(unid$)
            While Not (mDoc Is Nothing) 'Inner Loop
                If mDoc.ResourceName(0) = rName$ Then

                    <PRINT TO FILE CODE>

                End If
                Set mDoc = mView.GetNextDocument(mDoc) <--- This line here breaks the code**
            Wend
        End If
    End If
    Set rDoc = rView.GetNextDocument(rDoc)
Wend

助けていただければ幸いです。

4

2 に答える 2

1

事は非常に簡単です: unid を介してドキュメントを取得する場合、ビューからは取得しません。そうすれば、「次の」ドキュメントを取得できなくなります。ナビゲートできるようにするには、ビューからドキュメントを「再取得」する必要があります。

これを試して:

Dim viewNav as NotesViewNavigator
Set viewNav = mView.CreateViewNav
...
Set mDoc = db.Getdocumentbyunid(unid$)
'- now get the same document, but this time from view:
Set mDoc = viewNav.getEntry( mDoc ).Document

それは役立つはずです。

mDoc は同じドキュメントのままですが、今回はビューから初期化され、"GetNextDocument" で使用できます...

ところで、私の経験では、NotesViewNavigator を使用すると、ほとんどの場合、「ネイティブ」の NotesView メソッドを使用するよりもビューを循環する方が速くなります。

編集: NotesDocumentCollection にあるがそこから直接取得されていない NotesDocument がある場合、同じことが発生する可能性があります。次に、「ドキュメントはこのコレクションからのものではありません」というエラーが表示されます。同じ方法があります:Set doc=collection.GetDocument( doc )

于 2014-07-15T06:49:15.307 に答える