简体   繁体   中英

Set values in formula fields in crystal report from VB

I'm new in vb and crystal report so please help me from my problem. I'm assigning values using vb codes to a formula field from my crystal report. Here is my code:

 Dim report As CrystalDecisions.CrystalReports.Engine.ReportDocument
        report = New report_Student()
        report.DataDefinition.FormulaFields("student").Text = "Slone" & Chr(13) & "Thompson"
        frm_print.viewerReport.ReportSource = report
        frm_print.viewerReport.RefreshReport()
        frm_print.Show()

i place this in button click event. Now i have an error on running this, before it loads the crystal report from viewer this error shows:

The remaining text does not appear to be part of the formula.
Details: errorKind
Error in formula student:
'Slone
'

I guess as you have formula field (not text object) you should use formula there:

    report.DataDefinition.FormulaFields("student").Text = _
        ControlChars.Quote + "Slone" + ChrW(13) + "Thompson" + ControlChars.Quote

So, in result formula will contain one text literal ("Slone\\nThompson").

Not tried this, but hope it should work.

If not, then probably you need to use CR inner function ChrW() for newline in next way:

    report.DataDefinition.FormulaFields("student").Text = _
        ControlChars.Quote + "Slone" + ControlChars.Quote + _
        " + ChrW(13) + " + _
        ControlChars.Quote + "Thompson" + ControlChars.Quote

So, in result two text literals ("Slone" and "Thompson") will be concatenated with result of CR inner function ChrW().

In CR formula editor it will be shown as

    "Slone" + ChrW(13) + "Thompson"

But I expect 1st way should work.

You should use a report parameter instead of a formula. In case you need to modify the values inside the report use the parameter inside the formula

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.

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