Hello again.
I have made some progress regarding my test to split an existing Crystal Report file into multiple PDF files.
As I had previously stated, our application runs the Crystal Reports in several steps:
1) User opens the VFP form for a specific report (to select filters and then click the 'Report' button).
2) The 'Report' button will process the filters, build the SQL for the temporary DB tables, instantiate the General Report Screen (which is the interface where the user prints the report after adding a title, subtitle, and output option). Here in the 'Report' button logic, I added a step where if the user wants to split this report, I add an extra SQL for a temporary DB table that will contain the distinct values of the main table group1.
3) On the General Report Screen, the user will click on the 'Print' button, which will in effect create the temporary tables in the DB, instantiate the CrystalRuntime.Application and configure it prior to sending to selected output
4) At the time of creating the tables, I added a step where I identify that this report will be split, retrieve the distinct group values from the extra temporary table from step 2, and dump those values into a new property array.
5) In the executeReport() method, I loop through the property array values and configure additional CrystalRuntime.Application properties:
Code:
Case .Destination.value = '2' &&To File
if !empty(nvl(this.grp1valtable,'')) && Not empty means user wants to split report. Array has already been populated.
*TODO: User interface to define directory to export to. Currently saving to same directory where the application is located
oRpt.ExportOptions.DestinationType = 1 &&DiskFile
oRpt.ExportOptions.FormatType = 31 &&PDF
oRpt.ExportOptions.PDFExportAllPages = .t. &&Export all pages
for lnindex = 1 to alen(this.grp1valarray, 1) && Array contains distinct values for the primary group on the report
reportformula = "{@section1} = '" + alltrim(this.grp1valarray(lnindex, 1)) + "'"
reportname = "Management Report " + alltrim(this.grp1valarray(lnindex, 1)) + ".PDF"
[highlight #D3D7CF]oRpt.RecordSelectionFormula = reportformula[/highlight]
[highlight #D3D7CF]oRpt.ExportOptions.DiskFileName = reportname[/highlight]
oRpt.Export(.f.) && Export w/o prompting the user
endfor
else
oRpt.Export(.t.)
endif
The good news is that for my test report, where there are 14 distinct group1 values, I manage to generate 14 PDF files where the file name clearly displays each of the array values.
The bad news is that only the PDF file for the first value on the array has actual content. The remaining 13 PDF files are empty and only display the report headers/titles.
I have verified that while processing the array values, both the reportname and the reportformula variables (seen in the code snippet above) contain the expected values each time, i.e., for index = 14 (last value in the array) the
[highlight #D3D7CF]reportname variable = "Management Report 600304.PDF"[/highlight] and
[highlight #D3D7CF]reportformula variable = "{@section1} = '600304'"[/highlight]
so I am not sure why only the first value in the array is the one that generates a PDF with actual content, but the rest don't.
Prior to getting to the executereport() method described above, the following has been done:
Code:
...
thisform.createTables()
...
oRpt = .crystalcontrol.OpenReport(.RepFileName.Value)
...
for i=1 to oRpt.Database.Tables.Count
oRpt.Database.Tables(i).SetLogOnInfo(ogx.odbm.DataSourceName,ogx.odbm.DataSourceName,alltrim(ogx.odbm.userID),ogx.odbm.password)
endfor
...
executeReport(oRpt)
...
oRpt is not reset until after executeReport is done, so its DB connection and the DB tables should be available the whole time the splitting based on the new array is happening..
Any ideas/suggestions are welcome!
Regards,
Patricia Cu