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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add dynamic column in CR 7.0 1

Status
Not open for further replies.

jayeshp

Programmer
May 9, 2002
6
US
Hi Friends,

I am using CR 7.0 with VB(DSR) format.I also go though all above problems and got experience in it.

My query is :
I want to add new field to crystal report dynamically.
i.e. suppose i generate a employee report with two employeeid,employeename.Now i want to give provision to add add new database field(say 'address') from my vb-form.If user add new field(i.e. address), this field should be shown on my generated employee report.

Is this possible?
If you able to solve this then pl. reply me.
If not then tell me other way to generate reports.

Thanxs,
Jay.
 
You can use the Report Creation API for this - easiest way is through the Report Design Component in CR8+. This allows you to add fields through code.
Watch your licensing though - the Report Creation stuff needs additional licenses beyond the free runtime. Andrew Baines
Chase International
 

Hi AndrewBaines,

Can this possible in CR7.0(i.e using API).
pl. provide me some example for this(CR7.0/CR8.0) if possible.

Thanks Andrew..

Regards,
Jay.
 
It was only available before CR8 if you begged Crystal and then only if you were of strategic importance. You needed a license key included in your code that unlocked the functionality in the old Automation Interface.
In CR8, you get a sample app on the CD. Here's part of the sample code. As with all Crystal's samples, it's over complicated but it should help:

Private Sub DoDetails(SalaryFormula As FormulaFieldDefinition, _
TeamFormula As FormulaFieldDefinition, _
YearFormula As FormulaFieldDefinition)

Dim PlayerFormula As FormulaFieldDefinition
Dim PlayerObj As FieldObject
Dim SalaryObj As FieldObject
Dim TeamObj As FieldObject
Dim YearObj As FieldObject
Dim obj As Object
Dim LocX As Long ' The X-offset for the objects

LocX = 10
' Add the formulas to the formula fields collection
' A field must be recurring if you want to group on a field or
' automatically bind it to a data source.
' Putting "WhileReadingRecords" into the formula text makes the formula
' into a recurring field.
Const Recur = "WhileReadingRecords;" & vbNewLine
Set PlayerFormula = m_Report.FormulaFields.Add("Player", Recur & "Space(10)")
Set TeamFormula = m_Report.FormulaFields.Add("Team", Recur & "Space(10)")
Set SalaryFormula = m_Report.FormulaFields.Add("Salary", Recur & "$0.0")
Set YearFormula = m_Report.FormulaFields.Add("Year", Recur & "Space(10)")

' Add the fields only if the user wants them
' The player's name
If g_PlayerName = True Then
Set PlayerObj = m_Report.Sections(3).AddFieldObject(PlayerFormula, LocX, 0)
PlayerObj.Name = "Player"
PlayerObj.Width = 2600
LocX = LocX + 2100
End If

' Add the name of the team that the player belongs to
If g_TeamName = True Then
Set TeamObj = m_Report.Sections(3).AddFieldObject(TeamFormula, LocX, 0)
TeamObj.Name = "Team"
TeamObj.Width = 2800
LocX = LocX + 2000
End If

' Add the player's salary for that year
If g_Salary = True Then
Set SalaryObj = m_Report.Sections(3).AddFieldObject(SalaryFormula, LocX, 0)
SalaryObj.Name = "Salary"
SalaryObj.Width = 1500
SalaryObj.CurrencySymbolType = crCSTFloatingSymbol
SalaryObj.DecimalPlaces = 0
LocX = LocX + 1600
End If

' Add the year that the player made this amount of money
If g_YearName = True Then
Set YearObj = m_Report.Sections(3).AddFieldObject(YearFormula, LocX, 0)
YearObj.Name = "Year"
YearObj.Width = 2000
YearObj.HorAlignment = crRightAlign
If g_GroupByTeam Then YearObj.TextColor = vbWhite
End If

' Format all the fields in the details section (Section 3) to a more
' attractive format
For Each obj In m_Report.Sections(3).ReportObjects
obj.Font.Name = "Arial"
obj.Font.Size = 11
obj.Height = 250
Next

' Sort the fields ascending or descending, depending on the user's wishes
' Default to Descending order, unless the user wants to see those players
' that made less than a certain amount of money.
If g_SortOrder = "ASC" Then
m_Report.RecordSortFields.Add SalaryFormula, crAscendingOrder
Else
m_Report.RecordSortFields.Add SalaryFormula, crDescendingOrder
End If
End Sub
Andrew Baines
Chase International
 

Hi Andrew Baines,

Let me collect CR8.0 Licence CD... and hope so above code/sample will definately going to help.

I will get back to you after running/trying to add dynamic column.

can you provide me your email id.

Thanks Andrew.

Regards,
Jay.
 
Email's tricky - I'd normally charge for this sort of thing!
Post anything further on to this thread and I'll be notified automatically. Andrew Baines
Chase International
 
Hi Andrew Baines,

I haven't try above but i will.
My next query is : how can i display multiple detail section without using sub-report ?

Regards,
Jay.
 
If you want to show multiple records in the detail section go into the section expert and select the detail section and check 'format with multiple columns. then you will see a table for 'layout'. Adjust as needed. You should be able to get additional records, one under the other. Howard Hammerman,

Crystal Reports training, consulting, books, training material, software, and support. Scheduled training in 8 cities.
howard@hammerman.com
800-783-2269
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top