visual-studio VB6 / Crystal Report 8.5 错误:此处需要字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/103261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB6 / Crystal Report 8.5 error: A string is required here
提问by phill
I recently inherited an old visual basic 6/ crystal reports project which connects to a sql server database. The error message I get (Error# -2147191803 A String is required here) when I attempt to run the project seems to be narrowed down to the .Printout command in the following code:
我最近继承了一个旧的 Visual Basic 6/水晶报表项目,它连接到一个 sql server 数据库。当我尝试运行该项目时,我得到的错误消息(Error# -2147191803 A String is required here)似乎被缩小到以下代码中的 .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
During the run, the form shows up, the ParamDef variable sets the "company name" and when it gets to the Report.PrintOutline which prompts to print, it throws the error. I'm guessing the crystal report isn't receiving the "Company Name" to properly run the crystal report. Does any one know how to diagnose this...either on the vb6 or crystal reports side to determine what I'm missing here?
在运行过程中,表单出现,ParamDef 变量设置“公司名称”,当它到达提示打印的Report.PrintOut行时,它会抛出错误。我猜水晶报告没有收到“公司名称”来正确运行水晶报告。有没有人知道如何诊断这个……无论是在 vb6 还是水晶报告方面,以确定我在这里遗漏了什么?
UPDATE:
更新:
- inserted CStr(selected) to force DomainName to be a string
- inserted msgboxes into the for loop above and below the .setcurrentvalue line
- inserted Case "{?Company Name}" statement to see if that helps setting the value
- tried .AddCurrentValue and .SetCurrentValue functions as suggested by other forum websites
- ruled out that it was my development environement..loaded it on another machine with the exact same vb6 crystal reports 8.5 running on winxp prof sp2 and the same errors come up.
- 插入 CStr(selected) 强制域名为字符串
- 将 msgboxes 插入到 .setcurrentvalue 行上方和下方的 for 循环中
- 插入 Case "{?Company Name}" 语句以查看是否有助于设置值
- 尝试了其他论坛网站建议的 .AddCurrentValue 和 .SetCurrentValue 函数
- 排除这是我的开发环境..将它加载到另一台具有完全相同的 vb6 水晶报告 8.5 在 winxp prof sp2 上运行的机器上,并且出现了相同的错误。
and when I run the MsgBox(ParamDef.Value) and it also turns up blank with the same missing string error. I also can't find any documentation on the craxdrt.ParameterFieldDefinition class to see what other hidden functions are available. When I see the list of methods and property variables, it doesn't list SetCurrentValue as one of the functions. Any ideas on this?
当我运行 MsgBox(ParamDef.Value) 时,它也变成空白,并出现相同的缺失字符串错误。我也找不到关于 craxdrt.ParameterFieldDefinition 类的任何文档,以了解还有哪些其他隐藏函数可用。当我看到方法和属性变量的列表时,它没有将 SetCurrentValue 列为函数之一。对此有何想法?
回答by Arthur Miller
What is the value of your selected variable?
您选择的变量的值是多少?
Table.SetLogOnInfo ConnName, DBName, user, pass
DomainName = selected
'Set parameter Fields
Table.SetLogOnInfo ConnName, DBName, user, pass
DomainName = selected
'设置参数字段
If it is not a string, then that might be the problem. Crystal expects a string variable and when it doesn't receive what it expects, it throws errors.
如果它不是字符串,那么这可能是问题所在。Crystal 需要一个字符串变量,当它没有收到它期望的东西时,它会抛出错误。
回答by phill
selected is a string variable input taken from a form with a drop down select box. I previously put a message box there to ensure there the variable is passing through right before the Report.Printout and it does come up. DomainName variable is also declared as a string type.
selected 是从带有下拉选择框的表单中获取的字符串变量输入。我之前在那里放了一个消息框,以确保变量在 Report.Printout 之前通过,并且它确实出现了。DomainName 变量也被声明为字符串类型。
回答by nathaniel
Here's how I set my parameters in Crystal (that came with .NET -- don't know if it helps you).
这是我在 Crystal 中设置参数的方法(随 .NET 一起提供 - 不知道是否对您有帮助)。
Dim dv As New ParameterDiscreteValue
dv.Value = showphone
rpt.ParameterFields("showphone").CurrentValues.Add(dv)
回答by nathaniel
This can happen in crystal reports 8.5 if you changed the length of a string column you use in your report so that it exceeds 255 bytes. This can also happen if you change the column type from varchar to nvarchar (double byte string!)
如果您更改了报告中使用的字符串列的长度,使其超过 255 个字节,则在 Crystal Reports 8.5 中可能会发生这种情况。如果将列类型从 varchar 更改为 nvarchar(双字节字符串!),也会发生这种情况
The reason for this is that crystal reports 8.5 treats all strings longer than 255 bytes as memo fields.
这样做的原因是,Crystal 报告 8.5 将所有长度超过 255 字节的字符串视为备注字段。
I would suggest youe upgrade to crystal reports XI - the API has not changed that much.
我建议您升级到 Crystal Reports XI - API 没有太大变化。
回答by nathaniel
From my point of view you should get the same error message if you open the report in the Crystal Reports Designer and switch to preview mode. The Designer should also show you a message with the exact location of the problem, e.g. the field which can not be treated as a string.
在我看来,如果您在 Crystal Reports 设计器中打开报表并切换到预览模式,您应该会收到相同的错误消息。设计器还应向您显示一条消息,其中包含问题的确切位置,例如不能被视为字符串的字段。
The problem is not that a field longer than 255 bytes cannot be printed. The problem is that a field longer than 255 bytes cannot be used in a formula, as a sort criteria ...
问题不在于无法打印超过 255 个字节的字段。问题是不能在公式中使用超过 255 个字节的字段,作为排序标准......
回答by smbarbour
Here is a live example of setting the parameters that we use:
这是设置我们使用的参数的实时示例:
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
This is actually a sample written in VBScript for printing Crystal 8.5 reports, but the syntax is the same for VB6
这实际上是一个用VBScript编写的用于打印Crystal 8.5报表的示例,但语法与VB6相同

