Modifying report variables in Reporting service 2008 R2

I've seen multiple times where we create a Read / Write Report variable (Group variables are striclty Read only) but not able to find a way to over write the value during the report execution phase.

Here is a way to do it.

Assume that you've created a report variable named "Reportvariable1".

All you need is a piece of custom code.

Public Function SetVariableValue(val as Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.Variable)

val.Value = val.Value + 2

End Function

As simple as that. All i'm doing in the function is, take the report variable reference, add 2 to the existing value. That's it.

How you can call this function from your report item?


This will do the magic. Also note that in the above expression i'm just passing the variable reference and not its value.

You could always make some modifications in the way you want. For example, you want to modify the variable with a customized value and display the same in the textbox, here is what you need to do in the function.

Public Function SetVariableValue(val as Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.Variable, newval As Integer) as Integer

val.Value = val.Value + newval

Return Val.Value

End Function

And call it from a textbox,

=Code.SetVariableValue(Variables!Reportvariable1, ReportItems!Textbox1.Value)

Hope this helps!


[All the posts are AS-IS with no warranty]