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
助けていただければ幸いです。