The problem with my current code is that it overrides everything in existing Document collection with additional file I am trying to add. I want to add additional file but it becomes the only one existing in Document collection after running this code.
' Execute search for existing Document Collections
Set oObjectSearchResults = oVault.ObjectSearchOperations.SearchForObjectsByConditions(oSearchConditions, MFSearchFlagNone, False)
'MsgBox ("There were " & oObjectSearchResults.Count & " objects")
' Get a reference to existing Document Collection
Set oDocumentCollectionOVAP = oVault.ObjectOperations.GetObjectVersionAndProperties(oObjectSearchResults.Item(1).ObjVer)
' Add current file to Document Collection
lookup.Item = oOldDocumentOVAP.ObjVer.ID
lookup.Version = -1
lookups.Add -1, lookup
propertyValue.TypedValue.SetValueToMultiSelectLookup lookups
propertyValue.PropertyDef = MFilesAPI.MFBuiltInPropertyDef.MFBuiltInPropertyDefCollectionMemberDocuments
' Check out Document Collection
If Not (oVault.ObjectOperations.IsObjectCheckedOut(oDocumentCollectionOVAP.ObjVer.ObjID)) Then
oVault.ObjectOperations.CheckOut oDocumentCollectionOVAP.ObjVer.ObjID
End If
' Save changes to Document Collection object
Set oDocumentCollectionOVAP = oVault.ObjectOperations.GetLatestObjectVersionAndProperties(oDocumentCollectionOVAP.ObjVer.ObjID, True, False)
oVault.ObjectPropertyOperations.SetProperty oDocumentCollectionOVAP.ObjVer, propertyValue
' Check in Document Collection object
oVault.ObjectOperations.CheckIn oDocumentCollectionOVAP.ObjVer