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!

add fields to report at runtime

Status
Not open for further replies.

prettitoni

Programmer
Apr 22, 2004
74
US
I want to send fields to a crystal report at runtime, depending on the user's selection in a VB6 program. Is this possible? I'm using a dbaseIV database and ADO (DAO) in Crystal to set up the report and RDC in VB.
 
That depends on your software version.

You can dynamically change fields to some extent, just not data types for esxisting reports, so use generic field names in the report, or you can even create reports on the fly from scratch.

"Sending fields" is a bit generic, please post specifics.

Here are the sample apps:


Check the Report Creation API examples.

-k
 
Yes, it does.

The work around I've used (VB6 w/ RDC) is to create a report based off of a generic ADO query that returns six fields (fld1-fld6). I drag the fields onto the report, and create 6 formulas for the column headings (@col1-@col6). Then, at runtime, I can take any query that returns 6 fields or less, create an ADO recordset, set my column header formulas in the report based on those fields, then send the recordset to the report.

-dave
 
Hi dave. That sounds plausible, but I'm not sure I understand what you mean by "set my column header formulas in the report based on those fields
 
In design mode, I create 6 formulas (@col1, @col2, @col3, etc.) with nothing in them, and place them in the page header. At runtime, after creating the recordset, and just before the report is sent to a CRViewer, I loop through the fields of the recordset to set the column names:
Code:
Dim intMaxNumFlds As Integer

If rst.Fields.Count > 6 Then
    intMaxNumFlds = 6
Else
    intMaxNumFlds = rst.Fields.Count
End If

For i = 0 To intMaxNumFlds - 1
   crRpt.FormulaFields.GetItemByName("col" & _
        CStr(i + 1)).Text = "'" & rst.Fields(i).Name & "'"
Next i

-dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top