【问题标题】:Copy documents from a view to other database and remove it将文档从视图复制到其他数据库并将其删除
【发布时间】:2015-11-25 10:22:45
【问题描述】:

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

如果我删除有关 Call docA.Remove(True) 的行,代理将复制所有文档而不会出错。

有什么建议吗?

非常感谢!

【问题讨论】:

  • 我忘了说agent只执行一个文件,出现错误时agent停止。

标签: lotus-notes lotusscript lotus


【解决方案1】:

您删除了 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

您可以用消息框替换“打印”或发送电子邮件/编写日志文档,等等。但至少你这样知道错误号、错误文本和错误行...

【讨论】:

  • 你说得对,我必须经常使用句柄错误,我将在代码中引入,非常感谢您的帮助,它的工作原理!
【解决方案2】:

错误出现在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  
Loop

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-30
    • 2012-10-07
    • 2012-10-12
    • 2013-12-14
    • 2012-09-15
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多