我想将文档从数据库中的视图传输到其他数据库中的其他视图,因此我必须复制然后删除文档,因为notesdocument唯一的选项是copytodatabase。
所以我有这个代码:
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)的行,代理将复制所有文档而不会出错。
有什么建议?
非常感谢!
I want to transfer the docs from a view in a database to other view in other database, so i have to copy and then to remove the docs, because the only option that notesdocument has is copytodatabase.
So i have this code:
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 SubWhen i execute the agent at the end it shows me an error:
Function requires a valid ADT argumentIf i remove the line about Call docA.Remove(True) the agent will copy all documents without error.
Any advice?
Thanks a lot!
最满意答案
您删除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另外,最好在代码中有一个错误处理程序,以获取有关错误的最少信息:
第一行代码(直接在End Sub行之前):
On Error Goto ErrorHandler代码结束:
EndSub: Exit Sub ErrorHandler: Print Err & ", " & Error & " in line " & erl Resume EndSub您可以用消息框替换“打印”,或者发送电子邮件/写入日志文档,无论如何。 但至少你知道错误号,错误文本和错误行那样...
You delete docA and then you cannot get the next document.
Just use another "docNext" to keep ther information:
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 LoopIn addition it is a good practice to ALWAYS have an errorhandler in your code to get at least a minimum information about the error:
First line of code (directly before the End Sub line):
On Error Goto ErrorHandlerEnd Of Code:
EndSub: Exit Sub ErrorHandler: Print Err & ", " & Error & " in line " & erl Resume EndSubYou can replace the "print" by a messagebox or send an email / write a log document, whatever. But at least you know the error number, error text and error line that way...
更多推荐
发布评论