报告构建器的表达式以删除字段为空的线路断裂



我正在根据通过在线表单提交给SQL Server的数据来开发报告。一个部分是一个复选框列表,以指示所需的服务。我已经在报告构建器中写了一个表达式,将字段连接到一个列中,并且为了在记者中轻松阅读,决定添加一个马车返回 (vbcrlf(。

在等。

问题是每个字段都会导致运输返回,因此如果选择了第1,第8和12个服务,则可能存在巨大的空白。

如果字段为空或空白,是否有办法使表达式忽略VBCRLF?或针对不同或更好的解决方案的任何建议。

  1. 在设计视图中,右键单击报告边界外的设计表面,然后单击报告属性。
  2. 单击代码。
  3. 在自定义代码中,键入代码

Public Function ConcatFields(ByVal s As String) As String
   If String.IsNullOrEmpty(s) Then
      Return ""
   End If
   Return s + Environment.NewLine
End Function

然后调用该函数如下:

=Code.ConcatFields(Fields!Service1.Value) + Code.ConcatFields(Service2.Value) + Code.ConcatFields(Service3.Value) + Code.ConcatFields(Service4.Value) ETC. ETC.

mt的第一个反应是将整个表达式包裹在替换函数中,然后将2个连续的vbcrlf替换为一个单个

=replace(Fields!Service1.Value + (VbCrLf) + Service2.Value + (VbCrLf) + 
Service3.Value + (VbCrLf) + Service4.Value,Vbcrlf+VbCrLf,VbCrLf)

这里的问题是您3个空值仍然会产生2条新行,因此您可以嵌套替换函数,因此它应用了2或3次,或者您可以使用内联IF在添加一个值之前测试每个值新线

=Fields!Service1.Value + iif(Service2.Value is nothing or Service2.Value = "","",VbCrLf)  + Service2.Value + iif(Service3.Value is nothing or Service3.Value = "","",VbCrLf) etc etc

最新更新