將符合條件的文檔從一個庫拷貝到另一個庫,並將文檔從原庫刪除,壓縮原庫
Dim db1 As NotesDatabase
Dim db2 As NotesDatabase
Dim dcc As NotesDocumentCollection
Dim note As NotesDocument
Dim sqlSearch As String
Set db1 = New NotesDatabase("","database1.nsf")
Set db2 = New NotesDatabase("" ,"database2.nsf")
sqlSearch = ""
sqlSearch ="搜索條件"
Set dcc = db1.Search(sqlSearch,Nothing,0) '搜索
Set note = dcc.GetFirstDocument
If dcc.Count=0 Then
Msgbox("沒搜索到文檔,退出")
Exit Sub
End If
While Not(note Is Nothing)
Call note.CopyToDatabase(db2)
Set note = dcc.GetNextDocument(note)
Wend
dcc.RemoveAll(True) '刪除
Call db1.Compact '壓縮
Msgbox("完成")