Unable to archive documents to Archive DB in lotus notes

237 Views Asked by At

There is a agent to Archive documents to archive database with removing them from the current database, But when I run the agent some documents get archived and the archiving stops and getting error as "Archiving Pending Requests:4000:Line 33:User-defined error"

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
1

There are 1 best solutions below

4
On

Fortunately your code has an error handler... So we know exactly what line this error occurs in:

Call doc.Save(True, False)  

That means: The document that the code works on cannot be saved.

The error number 4000 unfortunately is a generic error that can mean a lot of things. I guess, that in your case the document has grown to large (>32k data in one field) and therefor cannot be saved.

I would change the code in that way, that it writes a log about the documents that could not be archived and just continues with the next document instead of crashing. Therefor you need also to change the logic, as the document will never disappear from the view if it cannot be saved:

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)