Copy documents from one db to another while retaining doc/resp relationships

Use this code to copy documents from one database to another while maintaining their document/response relationships. The DOCID's on the parents & $REF's on the children documents will not be changed. Note: The database portion of the ID will change, but not the actual document portion. The code below was used inserted in an agent.

Sub Initialize
	Dim session As New NotesSession
	Dim thisdb As NotesDatabase
	Dim db2 As NotesDatabase
	Dim collect As NotesDocumentCollection
	Dim doc As NotesDocument
	Dim Server$, Path$
	Set thisdb = session.CurrentDatabase
	Call GetServerAndPath(Server, Path)
	Set db2 = session.GetDatabase(Server, Path & "testdb2.nsf")
	Set collect = thisdb.UnprocessedDocuments
	If db2.IsOpen = True Then
		Call doc.CopyToDatabase(db2)
		Set doc = collect.GetNextDocument(doc)
	         Loop Until doc Is Nothing
	         Print "Database 2 is not open"
	End If
	Set doc = collect.GetFirstDocument

End Sub	

Function GetServerAndPath (server As String, path As String)

	Dim ss As New notessession
	Dim db As notesdatabase
	Dim i As Integer
	Set db=ss.currentdatabase
	For i=Len (db.filepath) To 1 Step -1
		If Mid(db.filepath,i,1)="\" Then
			If i > 1 Then
				path =Left (db.filepath, i-1) & "\"
			End If
			Exit For
		End If

End Function

Posted by fbrefere001 on Tuesday February 19, 2002