Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Report Parameter validation in ssrs report

I have created one SSRS report having begin date and end date. If I provide end date< start date it will execute the report as shown in the image enter image description here

But that condition I need to show a pop up "Please Check the start date and end date provided". How to do this?

like image 988
Alias Varghese Avatar asked Oct 17 '25 01:10

Alias Varghese


2 Answers

Click Report Menu then Report Properties.
Go to Code Tab and add similar code as per your requirement:

Function CheckDateParameters(StartDate as Date, EndDate as Date) as Integer
Dim msg as String
     msg = ""
     If (StartDate > EndDate)  Then
 msg="Start Date should not be later than End Date"
     End If
     If msg <> "" Then 
 MsgBox(msg, 16, "Report Validation")
 Err.Raise(6,Report)                    'Raise an overflow
     End If
End Function

And

Follow the Steps:

1.) Go the Report Parameters and add a parameter with the datatype is string.

2.) Check the Hidden checkbox and Allow blank value ckeckbox.

3.) From Default Values choose Non-Queried radio button and then press the FX button and paste this code.

=CODE.CheckDateParameters(<parameterStartdate>.Value,<parameterEnddate>.Value)

Then press OK.

See reference Link:

Easy Step by Step SSRS Parameter Validation Using Code & Conditional DataSet

like image 195
Hell Boy Avatar answered Oct 19 '25 23:10

Hell Boy


I'm answering this to chip in another possible solution when working with SQL/Server. If you just want to throw an error then simply amend your query SQL to raise an error on the SQL/Server side by adding something like this to the top of your SQL...

IF @ParEndDate < @ParStartDate
BEGIN
   RAISERROR('Please check the start date and end date provided', 16, 1);
   RETURN;
END;

The query won't run and the error message will be displayed in the report body.

like image 44
Ciarán Avatar answered Oct 19 '25 23:10

Ciarán



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!