I am wondering is there any way to shorten my current code. I am running one process in a lot of my macros and was thinking about subroutine. I have tried several approaches but can't get it work.
I am performing one search several times:
Sub AddFileToDC()
'... I am getting oDCSearchConditions from the search, then
' Execute the search
Dim oDCObjectSearchResults As MFilesAPI.ObjectSearchResults
Set oDCObjectSearchResults = oVault.ObjectSearchOperations.SearchForObjectsByConditions(oDCSearchConditions, MFSearchFlagNone, False)
' Get a reference to the existing document collection
Set oDocumentCollectionOVAP = oVault.ObjectOperations.GetObjectVersionAndProperties(oDCObjectSearchResults.Item(1).ObjVer)
Set oOldDocumentOVAP = oVault.ObjectOperations.GetObjectVersionAndProperties(oObjectSearchResults.Item(1).ObjVer)
End Sub
In all other macros I am performing another search from where I get oObjectSearchResults.
Instead of copying code above to all my macros, is it possible to do something like:
Sub Code1()
'... I am getting oSearchConditions from the search, then
' Execute the search
Dim oObjectSearchResults As MFilesAPI.ObjectSearchResults
Set oObjectSearchResults = oVault.ObjectSearchOperations.SearchForObjectsByConditions(oSearchConditions, MFSearchFlagNone, False)
AddFileToDC
End Sub
Now while running Code1 I am getting error message saying variable oDCObjectSearchResults not defined as it is in another sub AddFileToDC...
AddFileToDCneeds to have the dimensioning/setting removed for that variable being dimensioned/set inCode1. You will most likely need to dimension the variable globally so both subroutines can utilize it.