sqluser
sqluser

Reputation: 403

SSRS limiting number of characters for a parameter

How can I limit the number of characters a user can type for a parameter in SSRS?

For example, if the Data Type is set to TEXT, how to limit the user to type only 6 characters after Default value of "CL/" OR limit to total of 9 characters.

Upvotes: 1

Views: 5053

Answers (1)

Jonnus
Jonnus

Reputation: 3038

Unfortunately you can't perform validation as people write values, you can only handle them when the report is run. You can however use Code behind the report to perform some validation on your Parameters at run-time. Based on the result of this you can then either display the required data to instead return an error message.

To insert some code behind you right click the area around the report, Choose Report Properties, then Code.

Enter something like this into the code panel

Function Validate(param) as Boolean
     If len(cstr(param)) <= 9 Then
         Return"True"
     Else
         Return "False"
     End if
End Function

You can then refer to the result of this from a text box that displays an error as follows

Right click the text box and set the visibility to be

=iif(Code.Validate(Parameters!myInput.Value) = True, True, False)

Then if you enter a string of 9 or fewer characters you will get an error that you can use to inform the user of the proper format of your desired input string.

Instead of just making text boxes visible/invisible, you could also apply this to rectangles that store your report information. Also, you can use visual basic coding to alter the Code behind to perform more complicated parameter validation to check for you "CLI" string for example.

I hope this helps, let me know if you require further help.

Upvotes: 1

Related Questions