将文档从视图复制到其他数据库并将其删除(Copy documents from a view to other database and remove it)

编程入门 行业动态 更新时间:2024-10-24 08:27:44
将文档从视图复制到其他数据库并将其删除(Copy documents from a view to other database and remove it)

我想将文档从数据库中的视图传输到其他数据库中的其他视图,因此我必须复制然后删除文档,因为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 Sub

When i execute the agent at the end it shows me an error:

Function requires a valid ADT argument

If 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 Loop

In 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 ErrorHandler

End Of Code:

EndSub: Exit Sub ErrorHandler: Print Err & ", " & Error & " in line " & erl Resume EndSub

You 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...

更多推荐

本文发布于:2023-08-06 21:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1454997.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   文档   数据库   并将其   Copy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!