[英]VB6 / Crystal Report 8.5 error: A string is required here
我最近繼承了一個舊的Visual Basic 6 / Crystal Reports項目,該項目連接到sql server數據庫。 當我嘗試運行項目時,收到的錯誤消息(錯誤代碼-2147191803這里需要一個字符串)似乎在以下代碼中縮小為.Printout命令:
'Login to database Set Tables = Report.Database.Tables Set Table = Tables.Item(1) Table.SetLogOnInfo ConnName, DBName, user, pass DomainName = CStr(selected) 'Set parameter Fields 'Declare parameter holders Set ParamDefs = Report.ParameterFields 'Store parameter objects For Each ParamDef In ParamDefs With ParamDef MsgBox("DomainName : " + DomainName) Select Case .ParameterFieldName Case "Company Name" .SetCurrentValue DomainName End Select Select Case .Name Case "{?Company Name}" .SetCurrentValue DomainName End Select 'Flag to see what is assigned to Current value MsgBox("paramdef: " + ParamDef.Value) End With Next Report.EnableParameterPrompting = False Screen.MousePointer = vbHourglass 'CRViewer1.ReportSource = Report 'CRViewer1.ViewReport test = 1 **Report.PrintOut** test = test + 3 currenttime = Str(Now) currenttime = Replace(currenttime, "/", "-") currenttime = Replace(currenttime, ":", "-") DomainName = Replace(DomainName, ".", "") startName = mPath + "\crysta~1.pdf" endName = mPath + "\" + DomainName + "\" + DomainName + " " + currenttime + ".pdf" rc = MsgBox("Wait for PDF job to finish", vbInformation, "H/W Report") Name startName As endName Screen.MousePointer = vbDefault End If
在運行期間,將顯示該表單,ParamDef變量將設置“公司名稱”,並且當它到達提示打印的Report.PrintOut行時,將引發錯誤。 我猜水晶報表沒有收到“公司名稱”以正確運行水晶報表。 在vb6或Crystal報告方面,是否有人知道如何診斷此問題以確定我在這里缺少什么?
更新:
當我運行MsgBox(ParamDef.Value)時,它也出現空白,並出現相同的字符串錯誤。 我也找不到關於craxdrt.ParameterFieldDefinition類的任何文檔,以查看還有哪些其他隱藏函數可用。 當我看到方法和屬性變量的列表時,它沒有將SetCurrentValue列為功能之一。 有什么想法嗎?
您選擇的變量的值是多少?
Table.SetLogOnInfo ConnName,DBName,用戶,傳遞
域名=已選擇
'設置參數字段
如果不是字符串,則可能是問題所在。 Crystal需要一個字符串變量,當它沒有收到期望的字符串時,它將引發錯誤。
selected是從帶有下拉選擇框的表單中獲取的字符串變量輸入。 我之前在此處放置了一個消息框,以確保該變量在Report.Printout之前通過,並且確實出現了。 DomainName變量也聲明為字符串類型。
這是我在Crystal中設置參數的方法(.NET附帶的-不知道它是否對您有幫助)。
Dim dv As New ParameterDiscreteValue
dv.Value = showphone
rpt.ParameterFields("showphone").CurrentValues.Add(dv)
如果更改了報表中使用的字符串列的長度,使其超過255個字節,則在Crystal報表8.5中可能會發生這種情況。 如果將列類型從varchar更改為nvarchar(雙字節字符串!),也會發生這種情況。
原因是Crystal Report 8.5將所有長度超過255字節的字符串都視為備注字段。
我建議您升級到Crystal Report XI-API並沒有太大改變。
從我的角度來看,如果在Crystal Reports設計器中打開報表並切換到預覽模式,則應該收到相同的錯誤消息。 設計器還應向您顯示一條消息,其中包含問題的確切位置,例如,不能視為字符串的字段。
問題不在於不能打印長度超過255個字節的字段。 問題是,不能在公式中使用超過255個字節的字段作為排序標准...
這是設置我們使用的參數的實時示例:
For Each CRXParamDef In CrystalReport.ParameterFields
Select Case CRXParamDef.ParameterFieldName
Case "@start"
CRXParamDef.AddCurrentValue CDate("1/18/2002 12:00:00AM")
Case "@end"
CRXParamDef.AddCurrentValue Now
End Select
Next
這實際上是用VBScript編寫的用於打印Crystal 8.5報告的示例,但是語法與VB6相同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.