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:
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?
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.
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.
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)
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.
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, 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. The problem is that a field longer than 255 bytes cannot be used in a formula, as a sort criteria ...
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.