Move a Child Category to a Different Parent Category Example
This example moves a child category to a different parent category in the same level.
Note: In some cases, you cannot use a macro to set the properties of a category object. Your macro may appear valid but when you run the 'objCategory =' portion, you receive a message: 'This collection is Read Only in this context.' We recommend using the user interface instead.
Sub Example27()
Dim objTransApp As Object
Dim objModel As Object
Dim objDimension As Object
Dim objCategories As Object
Dim objCategory As Object
Dim objChildCategory As Object
Dim objParentCategory As Object
Dim strIBMCognos10Location As String
Dim strModelPath As String
Dim strModelSource As String
'Change these paths to match your installation
strIBMCognos10Location = "C:\Program Files\IBM\Cognos\c10\"
strModelSource = "Sales and Marketing.mdl"
strModelPath = strIBMCognos10Location & _
"webcontent\samples\models\Transformer8\EN\" & strModelSource
objTransApp = CreateObject("IBMCognosTransformer.ApplicationCtrl.1")
With objTransApp
.DataSourcePath = strIBMCognos10Location & "bin"
.TransdaPath = strIBMCognos10Location & "CS7Gateways\bin\TransDa.exe"
End With
objModel = objTransApp.OpenModel(strModelPath)
'Get a dimension
objDimension = objModel.Dimensions("Retailers")
'Get a collection of categories
objCategories = objDimension.DrillDowns(1).Categories
'Get the 5th category
objCategory = objCategories(5)
'Find the Spain child category
For child_category_index = 1 To objCategory.ChildCategories.Count
objChildCategory = objCategory.ChildCategories(child_category_index)
If objChildCategory.Name = "Spain" Then
'Find the Americas category and move the Spain child
category to it
For parent_category_index = 1 To objCategories.Count
objParentCategory = objCategories(parent_category_index)
If objParentCategory.Name = "Americas" Then
objChildCategory.ConnectWithCategory(objParentCategory)
Exit For
End If
Next
Exit For
End If
Next
With objModel
.SaveAs("Sales and MarketingX.mdl")
.Close()
End With
objParentCategory = Nothing
objChildCategory = Nothing
objCategory = Nothing
objCategories = Nothing
objDimension = Nothing
objModel = Nothing
objTransApp = Nothing
End Sub