Copy documents from a closed mail file to an opened one

hello,

I almost have this defeated. :slight_smile: I wrote an agent that copies documents from the contacts view from multiple source databases to a destination database. the agent is running on the destination database. the problem I am having now is I am getting an error message that states the source database is not open. does anyone know what method or function I need to use to copy the documents in a closed mail file over the the open mail file the agent is running on?

here is my code:

Sub Initialize

Dim session As New NotesSession

Dim currentDB As NotesDatabase

Dim db As Notesdatabase

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument



Set currentDB = session.CurrentDatabase





Dim AvariantV As Variant

AvariantV = 10



For AvariantV= 10 To 12

	

	Set db = session.GetDatabase("server1/independent", "filename0" + AvariantV +".nsf")

	Set view = db.GetView("($Contacts)")

	Set dc = view.getAllDocuments()

	Set doc = dc.GetFirstDocument().copytodatabase(currentDB)

	

	While Not(doc Is Nothing)

		

		Set doc = dc.GetNextDocument(doc).copytodatabase(currentDB)

		

	Wend

	

Next

End Sub

Subject: RE: copy documents from a closed mail file to an opened one (part 2)

The best way would be to check to see if the database is open before performing any operations.

You could use an “If” statement:

If db.IsOpen Then

Else

<do something else, like open the database; for example: Call db.Open(“”, “”)

then proceed to what you wanted to do>

End If

Subject: RE: copy documents from a closed mail file to an opened one (part 2)

Correction on my part.GetDatabase method should have opened up the database.

So, I agree with Jean’s question as to having access to the database.

Subject: RE: copy documents from a closed mail file to an opened one (part 2)

ok I corrected the problem. the parameters for “contacts” I had to leave the $ sign out. now I get the error after the scrip is run, “object variable not set”. I see that is found 54 documents in the view from the source database but nothing was copied into the destination database where the agent is run from.

here is the agent log:

Started running agent ‘get contacts’ on 11/03/2008 01:27:28 PM

Running on new or modified documents: 54 total

Found 54 document(s) that match search criteria

Ran LotusScript code

Done running agent ‘get contacts’ on 11/03/2008 01:27:29 PM

Subject: RE:RE: copy documents from a closed mail file to an opened one (part 2)

So, if we turn on the debugger, and step into this code line by line, on what line is it failing on?

Subject: RE: copy documents from a closed mail file to an opened one (part 2)

it’s failing at :

Set dc = view.getAllDocuments()

setting the document collection aka dc to the get all documents from the “contacts” view

Subject: RE:RE: copy documents from a closed mail file to an opened one (part 2)

Another thing I noticed.

There is no Dim of “view”. There should be a :

Dim view As NotesView

Also, when that is done, one finds that

getAllDocuments is not a method of the NotesView class.

Subject: RE:RE: copy documents from a closed mail file to an opened one (part 2)

understood. I made removed the get alldocuments class and added the view class. I am still getting the same error at the same place. here’s my updated code:

Sub Initialize

Dim session As New NotesSession 'gives script access to destination database'

Dim currentDB As NotesDatabase

Dim db As Notesdatabase

'Dim dc As NotesDocumentCollection REMOVED'

Dim doc As NotesDocument

Dim view As NotesView



Set currentDB = session.CurrentDatabase





Dim AvariantV As Variant

AvariantV = 10



For AvariantV= 10 To 12

	

	Set db = session.GetDatabase("server1/independent", "mail/" + "file0" + AvariantV +".nsf")

	

	If db.IsOpen Then 'checks to see if destination database is opened

		

		Set view = db.GetView("Contacts")

		'Set dc = view.getAllDocuments() REMOVED'

		Set doc = view.GetFirstDocument()

		Call doc.CopyToDatabase(currentDB)

		

		

	Else 

		

		Call db.open("stwebmail/brookstone", "store0" + AvariantV +".nsf")  'if database is not opened, open it

		Set view = db.GetView("Contacts")

		'Set dc = view.getAllDocuments() REMOVED'

		Set doc = view.GetFirstDocument()

		Call doc.CopyToDatabase(currentDB)

		

	End If

	

	While Not(doc Is Nothing)

		

		Set doc = view.GetNextDocument(doc)

		Call doc.CopyToDatabase(currentDB)

		

	Wend

	

Next

End Sub

Subject: RE: copy documents from a closed mail file to an opened one (part 2)

ok now I am getting an error “instance member getalldocuments does not exist”

Subject: You forgot to use Option Declare.

If you do this, it forces you to declare your variables. And if you declare your variables to their actual types (not Variant), then the compiler can tell you when you try to use a method, such as getalldocuments, that doesn’t exist. Read about NotesView in the Designer help. Where do you see this method described?

Subject: You forgot to use Option Declare.

I am seeing these methods under the view class catagory in designer help

Subject: GOT IT!

Andre you were correct! I got it with also a some help from my friend Chris. Thanks all of you guys. I certaintly hope that I will eventually possess the master expertise that you all have exhibited.

thanks a bunch!

Victor

Subject: copy documents from a closed mail file to an opened one -

Do you have access to these dbs?

For the follow-up

Date

Topic

Author

2

copy all documents from many databases to one

Victor Johnson

4

an agent to copy contact from inotes databases to another one

Victor Johnson

JYR