Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
 
					
				
		
hi,
I am using this macro to create a table box.
sub SeleccionarCampos
set val=ActiveDocument.Fields("CamposSelecPresup").GetPossibleValues
set TB = ActiveDocument.Sheets("Hoja8").CreateTableBox
for i=0 to val.Count-1
'msgbox(val.Item(i).Text)
TB.AddField val.Item(i).Text
next
end sub
Could be possible to give it always the same ID in order to replace the table box that have that ID?
Thank's!!!
 
					
				
		
 johnw
		
			johnw
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		You could replace the contents of the table box instead of adding a new one, and only display the table box if there is at least one value possible in "CamposSelecPresup". Attached is an example. See the "TABLE BOX ONLY?" section of the macro. Warning: I believe QlikView only keeps a single copy of each object, so if multiple users are changing it at the same time, I don't guarantee they'll get what they wanted. You may be better off just removing the old object and adding a new one, as I gather you do already.
Edit: Well, it's not letting me attach the application, so here's the macro.
sub rebuild()
 set AllowCalculation = ActiveDocument.Variables("AllowCalculation")
 AllowCalculation.SetContent 0, true 'Display the "Please wait..." text object
 ActiveDocument.GetApplication.WaitForIdle 'wait for QlikView to finish before modifying report
 set selectedExpressions = ActiveDocument.getField("Expressions").getSelectedValues
 set selectedDimensions = ActiveDocument.getField("Dimensions").getSelectedValues
 selectedExpressionMax = selectedExpressions.Count - 1
 selectedDimensionMax = selectedDimensions.Count - 1
 if selectedExpressionMax + selectedDimensionMax > -2 then 'bypass if nothing is selected
'--------------------------- TABLE BOX ONLY? ---------------------------------------------------
 if selectedExpressionMax = -1 then
 set table = ActiveDocument.getSheetObject("TB01")
 tableDimensionMax = table.GetColumnCount - 1
 for i = tableDimensionMax to 0 step -1 'remove existing dimensions
 table.removeField i
 next
 for j = 0 to selectedDimensionMax 'add selected dimensions
 table.addField selectedDimensions.Item(j).Text
 next
 else
'--------------------------- EXPRESSIONS ------------------------------------------------------
 set chart = ActiveDocument.getSheetObject("CH01")
 set chartProperties = chart.GetProperties
 set chartExpressions = chartProperties.Expressions
 chartExpressionMax = chartExpressions.Count - 1
 dim selectedExpression(100) 'runs slightly faster if first set up a simple array
 for j = 0 to selectedExpressionMax
 selectedExpression(j) = selectedExpressions.Item(j).Text
 next
 for i = 0 to chartExpressionMax 'for every possible expression defined to the chart
 e = chartExpressions.Item(i).Item(0).Data
 chartExpression = e.ExpressionVisual.Label.v
 expression = e.ExpressionData
 expression.Enable = false 'disable the expression
 for j = 0 to selectedExpressionMax 'check all selected expressions
 if selectedExpression(j) = chartExpression then 'if user selected the expression
 expression.Enable = true 'enable it
 j = 9999 'and exit the inner loop
 end if
 next
 next
 ActiveDocument.GetApplication.WaitForIdle
 chartProperties.GraphLayout.WindowTitle.v = "Custom Report"
 chart.SetProperties chartProperties
'--------------------------- DIMENSIONS --------------------------------------------------------
 chartDimensionMax = chart.GetColumnCount - 1
 for i = chartDimensionMax to 0 step -1 'remove existing dimensions
 chart.removeDimension i
 next
 for j = 0 to selectedDimensionMax 'add selected dimensions
 chart.addDimension selectedDimensions.Item(j).Text
 next
 end if
 end if
 AllowCalculation.SetContent 1, true 'allow dynamic report to recalculate
end sub
 
					
				
		
some idea?
 
					
				
		
 johnw
		
			johnw
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		You could replace the contents of the table box instead of adding a new one, and only display the table box if there is at least one value possible in "CamposSelecPresup". Attached is an example. See the "TABLE BOX ONLY?" section of the macro. Warning: I believe QlikView only keeps a single copy of each object, so if multiple users are changing it at the same time, I don't guarantee they'll get what they wanted. You may be better off just removing the old object and adding a new one, as I gather you do already.
Edit: Well, it's not letting me attach the application, so here's the macro.
sub rebuild()
 set AllowCalculation = ActiveDocument.Variables("AllowCalculation")
 AllowCalculation.SetContent 0, true 'Display the "Please wait..." text object
 ActiveDocument.GetApplication.WaitForIdle 'wait for QlikView to finish before modifying report
 set selectedExpressions = ActiveDocument.getField("Expressions").getSelectedValues
 set selectedDimensions = ActiveDocument.getField("Dimensions").getSelectedValues
 selectedExpressionMax = selectedExpressions.Count - 1
 selectedDimensionMax = selectedDimensions.Count - 1
 if selectedExpressionMax + selectedDimensionMax > -2 then 'bypass if nothing is selected
'--------------------------- TABLE BOX ONLY? ---------------------------------------------------
 if selectedExpressionMax = -1 then
 set table = ActiveDocument.getSheetObject("TB01")
 tableDimensionMax = table.GetColumnCount - 1
 for i = tableDimensionMax to 0 step -1 'remove existing dimensions
 table.removeField i
 next
 for j = 0 to selectedDimensionMax 'add selected dimensions
 table.addField selectedDimensions.Item(j).Text
 next
 else
'--------------------------- EXPRESSIONS ------------------------------------------------------
 set chart = ActiveDocument.getSheetObject("CH01")
 set chartProperties = chart.GetProperties
 set chartExpressions = chartProperties.Expressions
 chartExpressionMax = chartExpressions.Count - 1
 dim selectedExpression(100) 'runs slightly faster if first set up a simple array
 for j = 0 to selectedExpressionMax
 selectedExpression(j) = selectedExpressions.Item(j).Text
 next
 for i = 0 to chartExpressionMax 'for every possible expression defined to the chart
 e = chartExpressions.Item(i).Item(0).Data
 chartExpression = e.ExpressionVisual.Label.v
 expression = e.ExpressionData
 expression.Enable = false 'disable the expression
 for j = 0 to selectedExpressionMax 'check all selected expressions
 if selectedExpression(j) = chartExpression then 'if user selected the expression
 expression.Enable = true 'enable it
 j = 9999 'and exit the inner loop
 end if
 next
 next
 ActiveDocument.GetApplication.WaitForIdle
 chartProperties.GraphLayout.WindowTitle.v = "Custom Report"
 chart.SetProperties chartProperties
'--------------------------- DIMENSIONS --------------------------------------------------------
 chartDimensionMax = chart.GetColumnCount - 1
 for i = chartDimensionMax to 0 step -1 'remove existing dimensions
 chart.removeDimension i
 next
 for j = 0 to selectedDimensionMax 'add selected dimensions
 chart.addDimension selectedDimensions.Item(j).Text
 next
 end if
 end if
 AllowCalculation.SetContent 1, true 'allow dynamic report to recalculate
end sub
 
					
				
		
thank's a lot John!!!
I could have solved my problem.
Greetings,
Pol
