您可以检查参数表达式中的EndDate值,如果不正确,请将其设置为StartDate + 1 Month。
比如:
= IIF(DateDiff(DateInterval.Month, Parameters!StartDate.Value, Parameters!EndDate.Value) = 0, Parameters!EndDate.Value, AddDate(DateInterval.Month, 1, Parameters!StartDate.Value))
如果您只想通知用户,您可以放置一些具有适当格式(红色大字体)的隐藏文本框和有关日期参数不正确范围的消息。在隐藏表达式集中
= (DateDiff(DateInterval.Month, Parameters!StartDate.Value, Parameters!EndDate.Value) <> 0)
此外,您可以将这两个操作与自定义代码结合起来:
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) <> 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.ValidateDate(Parameters!StartDate.Value, Parameters!EndDate.Value)
在 tbDateParameterMessage 文本框的 Value 属性中:
= Code.DateMessage
并在隐藏属性表达式中:
= String.IsNullOrEmpty(Code.DateMessage)
编辑
但如果您想停止报告运行,请使用此自定义代码:
Public Function CheckDate(SDate as Date, EDate as Date) as Integer
Dim msg as String
msg = ""
If (SDate > EDate) Then
msg="Start Date should not be later than End Date"
End If
If msg <> "" Then
MsgBox(msg, 16, "Parameter Validation Error")
Err.Raise(6,Report) 'Raise an overflow
End If
End Function
取自SQLServerCentral forum。