Urgent : Agent Selected all documents copied from one database to other database in web not in client

Hi All, I have written an agent on web it is for selected documents. when i select more than one document but it is coping only one selected document but not other selected documents so here is code plz follow the code and help me what i m missing in the code.

Thx in Advance

Santosh

Sub Initialize

On Error Goto ErrHandle



Dim sess As New NotesSession

Dim db As  NotesDatabase

Dim db2 As New NotesDatabase("", "TEst123.nsf")

Dim doc As NotesDocument

Dim coll As NotesDocumentCollection

Dim i As Integer

Set db=sess.CurrentDatabase



Set coll=db.AllDocuments



For i=1 To coll.Count

Set doc=coll.GetNthDocument(i)

Call doc.CopyToDatabase(db2)

Next	

ErrHandle:

Print "<BR><H1>Your Document has been added.</H1><BR>"

Print "<BR><BR><BR><font size=1>Error code:" & Err & " in agent at line number:" &Str$(Erl) & ": " & Error$ 

End Sub

Subject: Urgent : Agent Selected all documents copied from one database to other database in web not in client

Use the UnprocessedDocuments to get all selected documents. Never use getNthDocument…its very slow (builds up new index after each doc)

Sub Initialize

On Error Goto ErrHandle Dim sess As New NotesSession

Dim db As NotesDatabase

Dim db2 As New NotesDatabase(“”, “TEst123.nsf”)

Dim doc As NotesDocument

Dim coll As NotesDocumentCollection

Dim i As Integer

Set db=sess.CurrentDatabase

Set coll=db.UnprocessedDocument

set doc = col.getFirstDocument

While not doc is nothing

Call doc.CopyToDatabase(db2)

set doc = col.getNextDocument (doc)

Wend

ErrHandle: Print “

Your Document has been added.


Print “


Error code:” & Err & " in agent at line number:" &Str$(Erl) & ": " & Error$

End Sub