问题描述
有一个代理程序可以将文档存档到存档数据库中,并从当前数据库中删除它们,但是当我运行该代理程序时,某些文档被存档了,存档停止了,并且由于 “归档待处理的请求:4000:第33行:用户定义的错误”
Option Public
'Use "LogError"
Sub Initialize
On Error Goto errorHandler
Dim s As New NotesSession
Dim Odb As NotesDatabase
Dim Oview As NotesView
Dim Oview2 As NotesView
Dim archdb As NotesDatabase
Dim archdbpath As String
Dim Ovc As NotesViewEntryCollection
Dim doc As Notesdocument
Dim archview As NotesView
Set Odb = s.CurrentDatabase
archdbpath = "Archiving\Archive2_DunkMatMaint911.nsf"
Set archdb = s.GetDatabase("BRUSPLNA101",archdbpath,False)
If Not(archdb.Isopen()) Then
'Logaction "Could not locate Archive database "
MsgBox "Could not locate Archive database "
Exit Sub
End If
'Set archview = archdb.GetView("vw_InArchivedDB")
Set Oview = Odb.GetView("Archive Requests 1") '----Archiving View Name
MsgBox "Going In While Loop"
Set doc = Oview.GetFirstDocument()
While Not(doc Is nothing)
Call doc.copyToDatabase(archdb)
doc.Archived = "True"
Call doc.Save(True,False)
Call Oview.Refresh
Set doc = Oview.GetFirstDocument()
Wend
Set Oview2 = Odb.GetView("Archive Requests 2")
Call Oview2.Refresh
Set Ovc = Oview2.AllEntries
Exit Sub
errorHandler:
'LogAction("Archiving Pending Requests: " + Format$(Err) + " : Line " + Format$(Erl) + " : " + Error$(Err) )
MsgBox "Archiving Pending Requests: " + Format$(Err) + " : Line " + Format$(Erl) + " : " + Error$(Err)
End Sub
解决方法
幸运的是,您的代码具有错误处理程序...因此,我们确切知道此错误发生在哪一行:
Call doc.Save(True,False)
这意味着:无法保存代码使用的文档。
不幸的是,错误号4000是一个通用错误,可能意味着很多事情。 我猜想,就您而言,文档已变大(一个字段中的数据超过32k),因此无法保存。
我将以这种方式更改代码,即编写有关无法归档的文档的日志,并继续处理下一个文档,而不会崩溃。因此,您还需要更改逻辑,因为如果无法保存文档,文档将永远不会从视图中消失:
Dim viwNav as NotesViewNavigator
Dim ve as NotesViewEntry
Set viwNav = Oview.CreateViewNavigator()
Oview.AutoUpdate = False
Set ve = viwNav.GetFirst()
While Not(ve Is Nothing)
Set doc = ve.Document
On Error Goto errorHandlerDoc
Call doc.CopyToDatabase(archdb)
doc.Archived = "True"
Call doc.Save(True,False)
NextDoc:
Set ve = viwNav.GetNext(ve)
Wend
On Error Goto errorHandler
Set Oview2 = Odb.GetView("Archive Requests 2")
Call Oview2.Refresh
Set Ovc = Oview2.AllEntries
Exit Sub
errorHandlerDoc:
Msgbox "Archiving Pending Requests: " + Format$(Err) + " : Line " + Format$(Erl) + " : " + Error$(Err) + " for document " + doc.UniversalId
Resume NextDoc
errorHandler:
'LogAction("Archiving Pending Requests: " + Format$(Err) + " : Line " + Format$(Erl) + " : " + Error$(Err) )
Msgbox "Archiving Pending Requests: " + Format$(Err) + " : Line " + Format$(Erl) + " : " + Error$(Err)