I am trying to put some embedded Visual Basic code into my report (RS 2005), using the "Code" section in the report properties.
Here's the function I'm trying to use:
Public Shared Function ReportTotal(ByVal IsUnitCost As Boolean,ByVal TotalDirectCosts As Double, ByVal SalaryBenefitsTotal As Double, ByVal IndirectRate As Double, ByVal SS_Screened As Integer, ByVal UnitRate As Double) As Double
If IsUnitCost Then
Return SS_Screened * UnitRate
Else
Return TotalDirectCosts + SalaryBenefitsTotal * IndirectRate
End If
End Function
Supposedly, after entering this you can access it in the expression for a field by typing the following: =Code.ReportTotal(... parameters ...)
However, when I try this, "ReportTalk" does not show up in the intellisense after I type "Code.". If I type it in anyway, a red squiggly line shows up under it, and if I attempt to preview the report, I get the following error: "The definition of report [report name] is invalid. Exception of type 'Microsoft.ReportingServices.ReportProcessing.ReportProcessingException' was thrown."
This is not a very helpful error message! I tried with and without "Public" and "Shared" and got the same thing.
What am I doing wrong?
Unfortunately, Custom code is not compiled until the report is published, so any custom methods will not show up in intellisense or be resolved (which results in the red underline) by the report designer.
If you are using RS 2005, then it should be evident in the exception message if the custom code generated the error. So, inorder to help you debug the issue I have a few questions:
What version of Reporting Services are you using?|||
Oh OK, you are right -- when I deploy the report, my code does work! Thank you very much.
You'd think there would be ONE mention of this little fact in SOME documentation, somewhere! It never would have occurred to me that the error was occurring only on preview.
In the SQL Server books online, the following is the entire entry for How to Add Code to a Report:
1. On the Report menu, click Report Properties.
Note: If the Report menu is not available, click within the report design area.
2. On the Code tab, in Custom code, type the code.
I kid you not. Anyway, thank you very much!
No comments:
Post a Comment