简体   繁体   English

VB6 / Crystal Report 8.5错误:此处需要一个字符串

[英]VB6 / Crystal Report 8.5 error: A string is required here

I recently inherited an old visual basic 6/ crystal reports project which connects to a sql server database. 我最近继承了一个旧的Visual Basic 6 / Crystal Reports项目,该项目连接到sql server数据库。 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: 当我尝试运行项目时,收到的错误消息(错误代码-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

During the run, the form shows up, the ParamDef variable sets the "company name" and when it gets to the Report.PrintOut line which prompts to print, it throws the error. 在运行期间,将显示该表单,ParamDef变量将设置“公司名称”,并且当它到达提示打印的Report.PrintOut行时,将引发错误。 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? 在vb6或Crystal报告方面,是否有人知道如何诊断此问题以确定我在这里缺少什么?

UPDATE: 更新:

  • inserted CStr(selected) to force DomainName to be a string 插入的CStr(selected)强制DomainName为字符串
  • inserted msgboxes into the for loop above and below the .setcurrentvalue line 将msgboxes插入.setcurrentvalue行上方和下方的for循环中
  • inserted Case "{?Company Name}" statement to see if that helps setting the value 插入案例“ {?Company Name}”语句以查看是否有助于设置值
  • tried .AddCurrentValue and .SetCurrentValue functions as suggested by other forum websites 尝试使用其他论坛网站建议的.AddCurrentValue和.SetCurrentValue函数
  • 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. 排除它是我的开发环境。将其加载到另一台计算机上,该计算机在winxp prof sp2上运行的vb6 crystal报告8.5完全相同,并且出现相同的错误。

and when I run the MsgBox(ParamDef.Value) and it also turns up blank with the same missing string error. 当我运行MsgBox(ParamDef.Value)时,它也出现空白,并出现相同的字符串错误。 I also can't find any documentation on the craxdrt.ParameterFieldDefinition class to see what other hidden functions are available. 我也找不到关于craxdrt.ParameterFieldDefinition类的任何文档,以查看还有哪些其他隐藏函数可用。 When I see the list of methods and property variables, it doesn't list SetCurrentValue as one of the functions. 当我看到方法和属性变量的列表时,它没有将SetCurrentValue列为功能之一。 Any ideas on this? 有什么想法吗?

What is the value of your selected variable? 您选择的变量的值是多少?

Table.SetLogOnInfo ConnName, DBName, user, pass Table.SetLogOnInfo ConnName,DBName,用户,传递
DomainName = selected 域名=已选择
'Set parameter Fields '设置参数字段

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需要一个字符串变量,当它没有收到期望的字符串时,它将引发错误。

selected is a string variable input taken from a form with a drop down select box. selected是从带有下拉选择框的表单中获取的字符串变量输入。 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. 我之前在此处放置了一个消息框,以确保该变量在Report.Printout之前通过,并且确实出现了。 DomainName variable is also declared as a string type. DomainName变量也声明为字符串类型。

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)

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. 如果更改了报表中使用的字符串列的长度,使其超过255个字节,则在Crystal报表8.5中可能会发生这种情况。 This can also happen if you change the column type from varchar to nvarchar (double byte string!) 如果将列类型从varchar更改为nvarchar(双字节字符串!),也会发生这种情况。

The reason for this is that crystal reports 8.5 treats all strings longer than 255 bytes as memo fields. 原因是Crystal Report 8.5将所有长度超过255字节的字符串都视为备注字段。

I would suggest youe upgrade to crystal reports XI - the API has not changed that much. 我建议您升级到Crystal Report XI-API并没有太大改变。

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. 从我的角度来看,如果在Crystal Reports设计器中打开报表并切换到预览模式,则应该收到相同的错误消息。 The Designer should also show you a message with the exact location of the problem, eg the field which can not be treated as a string. 设计器还应向您显示一条消息,其中包含问题的确切位置,例如,不能视为字符串的字段。

The problem is not that a field longer than 255 bytes cannot be printed. 问题不在于不能打印长度超过255个字节的字段。 The problem is that a field longer than 255 bytes cannot be used in a formula, as a sort criteria ... 问题是,不能在公式中使用超过255个字节的字段作为排序标准...

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相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM