Link to home
Start Free TrialLog in
Avatar of zerobro
zerobro

asked on

Editing SQL query statement in subreport

Hi Experts,

In crystal 8 or 8.5, is there a way to edit the subreport's query at runtime?
If this can be done, please show me a VB or Delphi code on how to do this.

TIA,
zerobro
Avatar of Mike McCracken
Mike McCracken

Yes it can be done.
the VB Crystal OCX Object has a property called SubReportToChange.  

CRReport.SubReportToChange = "YOUR SUBREPORT.RPT"
CRReport.ReplaceSelectionFormula = "SELECT WHATEVER"

If you need more than this I can provide it but it is on a different machine without internet access.

good luck
mlmcc
Avatar of zerobro

ASKER

Hi mlmcc,

You mean with CRReport.ReplaceSelectionFormula property, I can edit the subreport's SQL query? The "SELECT....FROM" statement? This is the one I need to edit. I need to modify the FROM area of the subreport's query.

zerobro
The ReplaceSelectionFormula doesn't really edit the query but rather replaces it when the VB program issues the CRReport.Action = 1 and runs the report.  I do this all the time with the report's query with no problem  I looked at the options VB provided for the CR object and saw you could designate which subreport to change.

Hope this helps.  If you want a complete example let me know and I'll add it at work tomorrow.

good luck
mlmcc
Avatar of zerobro

ASKER

Hi mlmcc,

Yes please...
Please show me an sample code lines on how to do this.

Thanks,
zerobro
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zerobro

ASKER

Hi mimcc...your solution more or less solved my problem...thanks...