將符合特定搜尋條件的文件從來源 Notes 資料庫(database1.nsf)複製至目標資料庫(database2.nsf),複製完成後刪除來源文件並壓縮來源資料庫以釋放空間。
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 = "搜尋條件" ' 例如: [Status]="Completed"
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
Call dcc.RemoveAll(True) ' 從來源資料庫永久刪除文件
Call db1.Compact ' 壓縮來源資料庫
Msgbox "跨庫複製、清理與壓縮作業完成"
NotesDatabase.Search(query, view, maxDocs):依公式語言條件檢索文件集合NotesDocument.CopyToDatabase(targetDb):將文件(含附件、Rich Text)完整複製至目標庫NotesDocumentCollection.RemoveAll(force):True 表示硬刪除(不進垃圾桶)NotesDatabase.Compact:整理資料庫碎片、回收未使用空間Compact 操作會暫時鎖定資料庫,建議離峰時段執行