1
votes

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:

        '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. 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?

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.

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?

6

6 Answers

1
votes

What is the value of your selected variable?

Table.SetLogOnInfo ConnName, DBName, user, pass
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.

1
votes

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.

1
votes

Here's how I set my parameters in Crystal (that came with .NET -- don't know if it helps you).

Dim dv As New ParameterDiscreteValue
dv.Value = showphone
rpt.ParameterFields("showphone").CurrentValues.Add(dv)
0
votes

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!)

The reason for this is that crystal reports 8.5 treats all strings longer than 255 bytes as memo fields.

I would suggest youe upgrade to crystal reports XI - the API has not changed that much.

0
votes

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.

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 ...

0
votes

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