I need to execute a custom code function when the report first loads, and I need it to only run once. Where do I put it?
To call table-valued function in a SSRS, we can use two ways: 1. Select Query Type as Text in Dataset Properties, then type query with select statement. Please refer to this similar thread: How to use a table- valued function as a datasource for SSRS report?.
To add embedded code to a report In Design view, right-click the design surface outside the border of the report and click Report Properties. Click Code. In Custom code, type the code. Errors in the code produce warnings when the report runs.
I'm not sure how the best way to do this is. I don't think you get any events to hook in to, but you could fudge it. For example, have the header call a function to set the title, and as a by-product call your custom code function once:
Public Dim ReportTitle As String = ""
Public Function GetTitleAndDoSomethingElse As String
If (ReportTitle = "") Then
ReportTitle = "My Report Title"
' Do your stuff that runs once here
End If
Return ReportTitle
End Function
Then in your report header have a text box that is set to:
=Code.GetTitleAndDoSomethingElse
Ugly, but should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With