Numeric Field Validation in SSRS

Introduction

In my previous article, you saw how to validate a date parameter in SSRS parameter validation using custom code.

Now in this article, we will see how to validate a numeric parameter value.

Let's start.

Step 1

We need to write VB code to validate the value as numeric. Here's the VB code to validate the numeric value.

Function IsInputNumeric(
  Number1 As String, Number2 As String
)  As String   Dim RetValue As String   If (
  IsNumeric(Number1)  and IsNumeric(Number2)
)  Then    RetValue = "Valid"    Else   RetValue = "Please Enter Valid Order ID!!"    End If   Return RetValue   End Function  

Function Description

I have written IsInputNumeric functions that accept the two parameters Number1 and Number2; then, I use the IsNumeric built-in function of VB to validate each number parameter and return a message accordingly.

Note

In the preceding function, I used two parameters for validation. You can use any number of parameters depending on requirements.

Step 2

Then we need to create one parameter, IsValidNumber, whose datatype should be Text, and the visibility of the parameter should be Internal.

Then go to the default values tab, specify a value, and call this function here.

Step 3

After the preceding step, we must validate both parameters before passing them to the dataset. Click on the button and write an expression.

Step 4

Now we need to add a TextBox to the SSRS report design and then go to the TextBox properties window and call the IsvalidNumber parameter in the value expression of the TextBox and then set the visibility of the TextBox.

Step 5

Then preview the SSRS report and test the preceding logic. I put a string in both TextBoxes, but my query accepts only a numeric value. So this message is for our user.


Similar Articles