2
votes

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!

2
I have forgotten to say that agent only execute one document, when the error appears the agent stop.David

2 Answers

4
votes

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

3
votes

The error occurs in line Set docA = vwA.GetNextDocument(docA) because you removed already docA and it can't be used as an parameter anymore.

Change your code to:

Do While Not( docA Is Nothing )
    Set docTemp = vwA.GetNextDocument(docA) 
    Call docA.CopyToDatabase(dbB)
    Call docA.Remove(True)
    Set docA = docTemp  
Loop