0
我有一個SSRS報告,工作得很好(有微小的變化)一些自定義代碼的實例,當我在Excel中使用VBA的測試數據運行,但在SSRS與失敗錯誤
爲文本框「textbox72」的值表達包含一個錯誤:對象沒有設置爲一個對象
該報告是一個簡單的表格報告的一個實例。自定義代碼比較審計報告中的「之前」和「之後」字符串,並應發回添加或刪除的詳細信息。字符串由char(10)分隔。字符串行只能添加或刪除。字符串行本身不會改變。沒有空字符串。我已經在Excel VBA中成功測試過了,所以我認爲代碼可能沒問題。有任何想法嗎?SSRS VBA代碼對象引用不設置到對象
在textbox72的代碼呼叫是
=iif(len(Fields!AOS.Value) > 0 and len(Fields!AfterAOS.Value) > 0,code.go_compare(ReportItems),"")
在報告中的代碼是:
Function go_compare(Items as ReportItems) as string
Dim j As Integer
Dim x As Integer
Dim Diff(50) As String
Dim DiffInd As Integer
Dim Intmatch As Integer
Dim StrDiff as string
Dim Arr() As String
Dim Arr1() As String
Dim StrVal As String
Dim StrFinal As String
Dim y As Integer
Dim Str1 as string
Dim Str2 as string
Str1 = items("AOS_1").value
Str2 = items("AfterAOS").value
StrFinal = ""
StrDiff = ""
For y = 0 To 1
Erase Diff
If y = 1 Then
StrVal = "Removed"
Arr = Split(Str1, Chr(10))
Arr1 = Split(Str2, Chr(10))
Else
StrVal = "Added"
Arr = Split(Str2, Chr(10))
Arr1 = Split(Str1, Chr(10))
End If
For j = 0 To UBound(Arr)
Intmatch = 0
For x = 0 To UBound(Arr1)
If Trim(Arr(j)) = Trim(Arr1(x)) Then
Intmatch = 1
End If
Next x
If Intmatch = 0 Then
Diff(DiffInd) = Trim(Arr(j))
DiffInd = DiffInd + 1
End If
Next j
StrDiff = StrDiff & StrVal & " Values" + vbCrLf
For j = 0 To UBound(Diff)
If Diff(j) = "" Then Exit For
StrDiff = StrDiff + Diff(j) + vbCrLf
Next j
If Len(StrDiff) > 16 Then
StrFinal = StrFinal + StrDiff
End If
StrDiff = ""
Next y
Return StrFinal
End Function
樣本數據(從Excel VBA試驗)
Dim StrStr1 As String
Dim StrStr2 As String
StrStr1 = "xxxx" & Chr(10)
StrStr1 = StrStr1 & "yyyy" & Chr(10)
StrStr1 = StrStr1 & "zzzz" & Chr(10)
StrStr1 = StrStr1 & "aaaa" & Chr(10)
StrStr1 = StrStr1 & "bbbb" & Chr(10)
StrStr1 = StrStr1 & "cccc" & Chr(10)
StrStr1 = StrStr1 & "dddd" & Chr(10)
StrStr2 = "xxxx" & Chr(10)
StrStr2 = StrStr2 & "yyyy" & Chr(10)
StrStr2 = StrStr2 & "zzzz" & Chr(10)
StrStr2 = StrStr2 & "aaaa" & Chr(10)
StrStr2 = StrStr2 & "bbbb" & Chr(10)
StrStr2 = StrStr2 & "dddd" & Chr(10)
StrStr2 = StrStr2 & "eeee" & Chr(10)
預期結果
Removed Values
cccc
Added Values
eeee
我不知道,但我'code.go_compare通知(ReportItems)''那是ReportItems'你從事功能go_compare(如項目ReportItems)使用類名稱' –
感謝@PaulOgilvie。我嘗試過在這種情況下單獨發送字段而不是整個報告項目集合的變體,但仍然會出現相同的錯誤,例如'= code.go_compare(Fields!AOS.Value,Fields!AfterAOS.Value)'(加上改變代碼來反映這一點) – MiguelH