I have a database that when a person clicks a button two documents are created. One person fills in one form and another person fills in the other. At some point I need to create a new document and merge the fields from the two separate docs to the newly created one. I have this code. The mergeview is cat. by UNID of a single document:Sub Initialize
Dim db As NotesDatabase
Dim mergeview As NotesView
Dim doc As notesdocument
Dim doc2 As notesdocument
Dim doc3 As notesdocument
Dim doc4 As notesdocument
Dim formval As String
Dim collection As notesdocumentcollection
Dim empdoc As notesdocument
Dim forms As String
Dim val1 As String
Dim val2 As String
Dim key As String
Dim newdoc As notesdocument
Dim empdocid As Variant
Set db = New NotesDatabase( "", "Test\perfguide.nsf" )
Set mergeview = db.getview("mergeview")
Set doc = mergeview.GetFirstDocument
While Not (doc Is Nothing)
If doc.form(0) = "Employee Form" Then
key = doc.GetItemValue("thisdocid")(0)
Else
If doc.form(0) = "Managers Form" Then
key = doc.GetItemValue("thisdocid")(0)
Else
If doc.form(0) = "Mgr Employee Form" Then
key = doc.GetItemValue("thisdocid")(0)
Else
If doc.form(0) = "Mgr Managers Form" Then
key = doc.GetItemValue("empdocid")(0)
End If
End If
End If
End If
Set collection = mergeview.GetAllDocumentsByKey(key, False)
If collection.Count = 2 Then
Set doc2 = collection.GetFirstDocument
Set doc3 = collection.GetNextDocument(doc2)
val1 = doc2.getitemvalue("Form")(0)
val2 = doc3.getitemvalue("Form")(0)
forms = val1 + " " + val2
End If
If forms = "Employee Form Mgr Employee Form" Then
Set doc4 = New NotesDocument( db )
doc4.form = "Employee Merged Form"
formval = "Employee Merged Form"
Call doc4.Save(True,True)
Else
If forms = "Mgr Employee Form Employee Form" Then
Set doc4 = New NotesDocument( db )
doc4.form = "Employee Merged Form"
formval = "Employee Merged Form"
Call doc4.Save(True,True)
Else
If forms = "Mgr Managers Form Managers Form" Then
Set doc4 = New NotesDocument( db )
doc4.form = "Managers Merged Form"
formval = "Managers Merged Form"
Call doc4.Save(True,True)
Else
If forms = "Managers Form Mgr Managers Form" Then
Set doc4 = New NotesDocument( db )
doc4.form = "Managers Merged Form"
formval = "Managers Merged Form"
Call doc4.Save(True,True)
End If
End If
End If
End If
Call doc2.CopyAllItems( doc4 , True )
Call doc4.Save(False,False)
Call doc3.CopyAllItems(doc4 , True)
doc4.form = formval
doc2.merged = "Merged"
success = doc2.ComputeWithForm( False, False )
If success Then
Call doc2.Save( True, True )
End If
doc3.merged = "Merged"
success = doc2.ComputeWithForm( False, False )
If success Then
Call doc2.Save( True, True )
End If
Call doc4.Save(True,True)
Call mergeview.Refresh
Set doc = mergeview.GetfirstDocument
wend
This does not seem to be working the way I would like it too. I can not see what I am doing wrong. Can I have some more eyes take a look. Been looking at it far too long.
Any suggestions…
TIA,
Steve