Question : Custom code in .rdlc report doesn't work

In a report we have in our project, we receive fields in each record that must be placed on their own line, but within the same column. For example, if we have 4 maintenance codes in the current record, we must show them in the same column. So, we must add a VbCrLf to the end of each field, then show the next one on the line beneath.

However, we cannot be sure which of the 4 may be null; therefore, we added a function to the Custom Code of the report (see attached code snippet). We intended this function to clear empty lines from a record when no value was available. If we just used the expression

=Fields!Value1 & VbCrLf & Fields.Value2 & VbCrLf ....etc...

then we'd end up with blank lines where the fields had no value. So, we wrote the function in the attached code snippet.

When we attempt to use the function in the Expression property of the field in question, we keep getting an 'Unrecognized Identifier' error, as if the function did not exist, as if it had never been added to the Code tab of the report. Of course when the report is run in the program, we get the ever-popular '#Error' string as our column value.

Question:  WTF???

   
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
Public Function FmtRptField(ByVal input As String) As String
        Dim szResult As String = ""
        If input.length > 0 Then
            szResult = input & vbcrlf
        End If
        Return szResult
End Function
Open in New Window Select All

Answer : Custom code in .rdlc report doesn't work

Like you, I get the Unrecognized Identifier in the expression window when I hover over the function name however the report runs ok. I suspect that the #Error you are getting is because you are passing null values to the function. Try using this in the custom code to see if it corrects the problem

        If Not String.IsNullOrEmpty(input) AndAlso input.length > 0 Then
            szResult = input & vbcrlf
        End If
Random Solutions  
 
programming4us programming4us