Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can check the EndDate value in parameter expression, and if it's incorrect, set it to StartDate + 1 Month.<br> Something like:</p> <pre><code>= IIF(DateDiff(DateInterval.Month, Parameters!StartDate.Value, Parameters!EndDate.Value) = 0, Parameters!EndDate.Value, AddDate(DateInterval.Month, 1, Parameters!StartDate.Value)) </code></pre> <p>If you just want notify user, you can place some hidden text box with appropriate formatting (red big font) and message about date parameters incorrect range. In Hidden expression set</p> <pre><code>= (DateDiff(DateInterval.Month, Parameters!StartDate.Value, Parameters!EndDate.Value) &lt;&gt; 0) </code></pre> <p>Also, you can combine both actions with custom code: </p> <pre class="lang-vb prettyprint-override"><code>Public DateMessage As String Public Function ValidateDate(StartDate As DateTime, EndDate As DateTime) As DateTime Dim ResultDate As DateTime If (DateDiff(DateInterval.Month, StartDate, EndDate) &lt;&gt; 0) Then ResultDate = AddDate(DateInterval.Month, 1, StartDate) DateMessage = String.Format("End Date parameter value {0} was out of range and was changed to {1}", EndDate, ResultDate) Else ResultDate = EndDate End If End Function </code></pre> <p>Then, in Parameter value expression:</p> <pre><code>= Code.ValidateDate(Parameters!StartDate.Value, Parameters!EndDate.Value) </code></pre> <p>In Value property of tbDateParameterMessage textbox:</p> <pre><code>= Code.DateMessage </code></pre> <p>And in Hidden property expression:</p> <pre><code>= String.IsNullOrEmpty(Code.DateMessage) </code></pre> <p><strong>EDIT</strong> But if you want to stop report running, use this custom code:</p> <pre class="lang-vb prettyprint-override"><code>Public Function CheckDate(SDate as Date, EDate as Date) as Integer Dim msg as String msg = "" If (SDate &gt; EDate) Then msg="Start Date should not be later than End Date" End If If msg &lt;&gt; "" Then MsgBox(msg, 16, "Parameter Validation Error") Err.Raise(6,Report) 'Raise an overflow End If End Function </code></pre> <p>It's taken from <a href="http://www.sqlservercentral.com/Forums/Topic537763-145-1.aspx" rel="nofollow noreferrer">SQLServerCentral forum</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload