我希望将文档从数据库中的视图转移到其他数据库中的其他视图,因此必须复制然后删除文档,因为notesdocument拥有的唯一选项是复制数据库。
所以我有个密码:
Option Public
Option Declare
Sub Initialize()
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim dbB As New NotesDatabase(db.Server,"Desarrollo\Formular_CL02.nsf")
Dim vwA As NotesView
Dim vwB As NotesView
Dim docA As NotesDocument
Dim docB As NotesDocument
'Open the database
If Not (dbB.isopen) Then
Call dbB.open(db.Server,"Desarrollo\Formular_CL02.nsf")
End If
'Get the views
Set vwA = db.getView( "TestDevelop" )
Set vwB = dbB.getView( "TestDevelop" )
Set docA = vwA.GetFirstDocument
Do While Not( docA Is Nothing )
If docB Is Nothing Then
Call docA.CopyToDatabase(dbB)
Call docA.Remove(True)
End If
Set docA = vwA.GetNextDocument(docA)
Loop
End Sub当我在最后执行代理时,它会显示一个错误:
Function requires a valid ADT argument如果删除有关调用docA.Remove(True)的行,则代理将无错误地复制所有文档。
有什么建议吗?
非常感谢!
发布于 2015-11-25 10:57:47
如果删除docA,则无法获得下一个文档。
只需使用另一个"docNext“来保存这些信息:
Dim docNext as NotesDocument
Set docA = vwA.GetFirstDocument
Do While Not( docA Is Nothing )
Set docNext = vwA.GetNextDocument(docA)
If docB Is Nothing Then
Call docA.CopyToDatabase(dbB)
Call docA.Remove(True)
End If
Set docA = docNext
Loop此外,在代码中始终有一个错误处理程序以获得有关错误的最小信息是一个很好的实践:
第一行代码(直接在末尾子行之前):
On Error Goto ErrorHandler“守则”末尾:
EndSub:
Exit Sub
ErrorHandler:
Print Err & ", " & Error & " in line " & erl
Resume EndSub你可以用一个消息盒代替“打印”,或者发送电子邮件/写日志文档,什么都可以。但至少你知道错误号,错误文本和错误行.
发布于 2015-11-25 10:58:38
错误发生在行Set docA = vwA.GetNextDocument(docA)中,因为您已经删除了docA,并且不能再将它用作参数。
将代码更改为:
Do While Not( docA Is Nothing )
Set docTemp = vwA.GetNextDocument(docA)
Call docA.CopyToDatabase(dbB)
Call docA.Remove(True)
Set docA = docTemp
Loophttps://stackoverflow.com/questions/33913917
复制相似问题