Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy all folders from mail file

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
Hi Pascal! Been a while! Have a little problem. I have a user who has 100+ folders set up in her mail file. Another user needs all the folders set up in their mail file. I've got this little script to put in a button to send to the other user in order to copy all the files, but I get a type mismatch error on the bold line and I'm not sure what needs to be done to fix it. I commented out the section that copies the documents into the new folder because I just need the structure, not the contents.

Could you take a look and make suggestions?

thanks!
les

Code:
Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
	
Dim SourceServer As Variant
Dim SourceDatabase As Variant
Dim DestServer As Variant
Dim DestDatabase As Variant
Dim FolderString As Variant
	

Dim SourceDB As New NotesDatabase("Domino1/MetCt","mail\rhill.nsf")
Dim DestDB As New NotesDatabase("Domino1/MetCt","mail\landrews.nsf")
	
Dim viewTitle As NotesView
Dim colViewEntries As NotesViewEntryCollection
Dim doc As NotesDocument
Dim views As Variant
Dim nextdoc As NotesDocument
Dim newdoc As NotesDocument
Dim x As Integer
	
[b]views = SourceDB.Views 'all view in the data base[/b]
FolderString = "Saved"
Forall v In views 'Loop through all views
If Left(v.Name, Len(FolderString)) = FolderString Then
If v.IsFolder Then 'is it a folder?
x = 0
'Print "Copying folders " & v.Name
Call DestDB.EnableFolder(v.Name) 'Copies folder if it doesn't exist
Set viewTitle = SourceDB.GetView(v.Name)
Set colViewEntries = viewTitle.AllEntries 'Make an Entrycollection of all entries in folder
Set doc = viewTitle.GetFirstdocument
				
'While Not doc Is Nothing 'Loop through all docs in the Entrycollection
'x=x+1
'Print "Copying documents : " & x & " to " & v.Name & " Folder"
'Set newdoc = doc.CopyToDatabase(DestDB)
'Call newdoc.PutInFolder( v.Name )
'Set nextdoc = viewTitle.GetNextDocument(doc)
'Set doc = nextdoc
'Wend
				
End If
End If
End Forall 
End Sub

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases: The Fundamentals of Relational Database Design
 
Hi Leslie !

Umm, I'm sorry to say, but I don't get an error when I run the code locally.

I first put the code in an agent (because I'm lazy), and it worked fine. Of course, I had to change server and db names, but other than that it's your code.

Then I went and created a draft with a button and pasted it in there - no problem either.

Therefor, I think we can conclude that you probably have an access issue - one of the two dbs cannot be opened, or something like that.

In any case, locally the code runs fine. So it's not a code issue, it's a missing object issue. You'll have to find which one is missing.

Ciao !

Pascal.
 
nice to know it's just me!

thanks for checking it out.

les
 
Can you tell me which permissions need to be set? It still doesn't appear to work.

thanks!
me
 
Sorry for being late.
I would suggest modifying the code with a few validation checks :

Code:
Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession

Dim viewTitle As NotesView
Dim colViewEntries As NotesViewEntryCollection
Dim doc As NotesDocument
Dim views As Variant
Dim nextdoc As NotesDocument
Dim newdoc As NotesDocument
Dim x As Integer
Dim SourceServer As Variant
Dim SourceDatabase As Variant
Dim DestServer As Variant
Dim DestDatabase As Variant
Dim FolderString As Variant
    

Dim SourceDB As New NotesDatabase("Domino1/MetCt","mail\rhill.nsf")
Dim DestDB As New NotesDatabase("Domino1/MetCt","mail\landrews.nsf")

If sourceDB.isopen then
    If destDB.isopen then
    
views = SourceDB.Views 'all view in the data base
FolderString = "Saved"
Forall v In views 'Loop through all views
If Left(v.Name, Len(FolderString)) = FolderString Then
If v.IsFolder Then 'is it a folder?
x = 0
'Print "Copying folders " & v.Name
Call DestDB.EnableFolder(v.Name) 'Copies folder if it doesn't exist
Set viewTitle = SourceDB.GetView(v.Name)
Set colViewEntries = viewTitle.AllEntries 'Make an Entrycollection of all entries in folder
Set doc = viewTitle.GetFirstdocument
                
'While Not doc Is Nothing 'Loop through all docs in the Entrycollection
'x=x+1
'Print "Copying documents : " & x & " to " & v.Name & " Folder"
'Set newdoc = doc.CopyToDatabase(DestDB)
'Call newdoc.PutInFolder( v.Name )
'Set nextdoc = viewTitle.GetNextDocument(doc)
'Set doc = nextdoc
'Wend

End If
End If
End Forall
End If
End If
End Sub

That way, we'll know if the database objects are correctly opened.

Pascal.
 
no problem, this isn't top on my priority list either!

I've added a messagebox to see where it's failing:
Code:
Sub Click(Source As Button)
	Dim ws As New NotesUIWorkspace
	Dim session As New NotesSession
	
	Dim viewTitle As NotesView
	Dim colViewEntries As NotesViewEntryCollection
	Dim doc As NotesDocument
	Dim views As Variant
	Dim nextdoc As NotesDocument
	Dim newdoc As NotesDocument
	Dim x As Integer
	Dim SourceServer As Variant
	Dim SourceDatabase As Variant
	Dim DestServer As Variant
	Dim DestDatabase As Variant
	Dim FolderString As Variant
	
	
	Dim SourceDB As New NotesDatabase("Domino1/MetCt","mail\rhill.nsf")
	Dim DestDB As New NotesDatabase("Domino1/MetCt","mail\landrews.nsf")
	
	If sourceDB.isopen Then
		If destDB.isopen Then
			
			views = SourceDB.Views 'all view in the data base
			FolderString = "Saved"
			Forall v In views 'Loop through all views
				If Left(v.Name, Len(FolderString)) = FolderString Then
					If v.IsFolder Then 'is it a folder?
						x = 0
'Print "Copying folders " & v.Name
						Call DestDB.EnableFolder(v.Name) 'Copies folder if it doesn't exist
						Set viewTitle = SourceDB.GetView(v.Name)
						Set colViewEntries = viewTitle.AllEntries 'Make an Entrycollection of all entries in folder
						Set doc = viewTitle.GetFirstdocument						
					End If
				End If
			End Forall
		Else
			Messagebox "Rob''s mail not available"
		End If
	Else
		Messagebox "Leslie''s mail not available"
	End If
End Sub
And you're right, the database is not open. However, when I try to open the database that doesn't work either!

any other suggestions?

leslie
 
Database not open ? That's either an access issue, or the db is corrupt.
Check the ACL and make sure you have access. Or check with the admin and ask for a fixup on it.

Pascal.
 
I've been given Manager Rights in the ACL for both mail files with all the options checked.
 
no, even after making that change to the ACL, the code above STILL gives me the 'Leslie's mail not available' error!

les
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top