Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace DB Fields

Status
Not open for further replies.

jedownsjr

IS-IT--Management
Jun 2, 2003
121
US
Is it possible to write a program (probably using the RDC) to replace one database field in a report with another? For example, if your database table is changed and you need to replace FieldA with FieldB in your report. I'm hoping to find a way to do this programmatically by opening a report file, replacing the field in the report, then saving the updated report file. Is there some type of method that can be used to replace fields?
 
As you might guess, it's dependent upon the edition/version of your software.

Another way to approach this is to use formulas in the report rather than fields, and then you can use parameters to change what is used in the formala, such as:

If {?FieldChangingParm} = "Name" then
{table.name}
else
{table.description}

You would then use this formula for grouping/display instead of the fields.

Since you've brought up the RDC, here are the sample apps:


Here's an example to create a report:


Try posting technical information when requesting it.

-k
 
That's a creative solution ... but unfortunately, I need to update 100's of existing reports where the fields are already placed in the reports -- a huge job if done manually. (BTW, our report files are created in CR 8.5 Professional, but I also have CR 8.5 Developer which gives me access to the RDC.) I know how to create a simple report from scratch using the RDC and the designer in VB, but I'm not sure how to save the report I create programmatically to a regular Crystal Report (.rpt) file -- knowing that would be helpful. But I also figured there is some way to replace one field with another, since you can access report objects (including DB fields) to see their value (name of the DB field) -- I just don't know a method to use. Here's what I had in mind, if you have any suggestions or can point me to any specific sample applications that do any of these steps:

1. Loop through the report objects, determine which are DB fields, then identify those DB fields.
2. Replace FieldA with Field1 (or FieldB with Field2, etc.) -- replacing with the new field names.
3. Finish looping through all the DB fields until comlete.
4. Save the updated .rpt file (somehow).
5. Follow a similar approach for DB fields used in select criteria, formulas, etc.

It SOUNDS simple enough ... but are there RDC methods that can accomplish this programmatically? Thanks for any help.
 
Thank you for the links ... this gets me a little more on track. Since I can identify my DB fields, I can probably try a delete & then an add, which will accomplish the same thing as a replace. Still didn't see anything on saving a dynamically-produced or dynamically-altered report file (created at run-time), but maybe I will find something on that eventually.
Thanks again!
 
To save a report after you've messed around with it programmatically, just call the SaveAs method when you're done:
[tt]
Report.SaveAs "c:\xxx.rpt", cr80FileFormat
[/tt]
Your thought about deleting and adding fields is right on. Just make sure you get the Top and Left properties of the field you're deleting so you know where to put the 'new' field. I think that deleting a field might also delete its matching column header, so you might look out for that as well.

-dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top