Hi..

I have done some programs in VB6 (SQL Database). With the Crystal report (Vertion 4).

Now I wanted to do these things with Crystal-9. But the procedure to pass values to “Formulas and “Selection Formula is different and I can not get it done.

So pls can u give me a small sample code for it. I’ll show u a sample how I have get it done in Crystal-4.

Ex.
This is how i have pass values to “Formulas

CrystalReport1.Formulas(0) = "PAWBNo='" & Trim(Text11.Text) & "'"
CrystalReport1.Formulas(1) = "AWB_Pcs_Wgt='" & Trim(Text13.Text) & "'"
CrystalReport1.Formulas(2) = "CoName='" & Trim(Text6.Text) & "'"


This is how i have pass values to “Selection Formulas :-

CrystalReport1.SelectionFormula = "{PF_DOrder.SerNo} = '" + Trim(Text17.Text) + "'"
CrystalReport1.Action = 2 'Display


pls. write to me...i'm runing out of time..

Appreciate u’r help..

Bassa

Dani AI

Generated

Short, practical answer for : in Crystal 9 from VB6 use the RDC/CRAXDRT Report object — set the selection filter with the report’s RecordSelectionFormula and override formula fields via the FormulaFields collection (each item has a Text property you can set). The CRAXDRT model exposes a Check method so you can validate a changed formula before viewing. (doczz.net)

Example (VB6 with a reference to the Crystal Reports 9 ActiveX Designer Run Time Library):

' Add reference to CRAXDRT in Project->References
Dim crApp As CRAXDRT.Application
Dim crRpt As CRAXDRT.Report

Set crApp = New CRAXDRT.Application
Set crRpt = crApp.OpenReport(App.Path & "\MyReport.rpt")

crRpt.DiscardSavedData
crRpt.RecordSelectionFormula = "{PF_DOrder.SerNo} = '" & Trim(txtSerNo.Text) & "'"

' Set formula fields (by index or name)
crRpt.FormulaFields(0).Text = Chr(39) & Trim(txtPAWB.Text) & Chr(39)   ' string literal wrapped in single quote
crRpt.FormulaFields(1).Text = CStr(Val(txtPcsWgt.Text))               ' numeric value

' Validate formula change
Dim ok As Boolean, errMsg As String
crRpt.FormulaFields(0).Check ok, errMsg
If Not ok Then MsgBox "Formula error: " & errMsg

CRViewer1.ReportSource = crRpt
CRViewer1.ViewReport

A few gotchas and troubleshooting tips:

  • When you replace a formula at runtime use Crystal syntax (not Basic). Literal text must be quoted inside the formula text — using Chr(39) (') or Chr(34) (") is a safe way to inject quotes from VB. (crystalreportsonlinetraining.com)
  • If formula names contain unusual characters you can avoid name problems by setting formulas by index (FormulaFields(i).Text), which has solved type/name errors for others. (stackoverflow.com)
  • Always call Check (or handle the returned error string) after changing a formula to catch syntax issues before displaying the report. (doczz.net)

If the project uses only a viewer-control wrapper (no RDC object), some data-definition changes are limited — the reliable pattern is to open the report through CRAXDRT, make changes there, then point the viewer at that Report object. (doczz.net)

This approach matches what you already found for selection formulas and gives a direct, repeatable way to push values into regular formula fields at runtime.

Hi….

I have attached a very simple code to show u how I have tried this with Crystal 8. . I was able to find the solution for “Selection formula.

But Still I couldn’t find a way to pass a value Normal “Formula. Can somebody c what the :?: here is…???


Thanking u
Bassa

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.