Solved

Accessing Report Field Collection

Posted on 2001-07-27
17
409 Views
Last Modified: 2007-12-19
How can I access the properties of fields in a report which has fields from a data definition (ttx) file? I want to iterate through the field collection of the report in vb and get the field names.

Do I have to iterate through each field type eg Formula and Sort field collections?
0
Comment
Question by:rhubarbtwo
  • 11
  • 6
17 Comments
 
LVL 12

Accepted Solution

by:
DRRYAN3 earned 60 total points
ID: 6326841
Use the CRAXDRT library

Dim crAppl As CRAXDRT.Application
Dim crRep As CRAXDRT.Report
Dim rs As ADODB.Recordset

' watch these two vars for answer to your question
dim field1DBFieldName as string
dim field1Name as string

' bunch of code to setup your recordset and load the data into it

Set crAppl = New CRAXDRT.Application
Set crRep = crAppl.OpenReport("C:\my documents\sample.rpt")
' bunch of code to setup your recordset and load the data into it
crRep.Database.Tables(1).SetDataSource rs, 3

field1DBFieldName = crRep.database.tables.item(1).fields.item(1).DatabaseFieldName
field1Name = crRep.database.tables.item(1).fields.item(1).Name

CRViewer1.ReportSource = crRep
CRViewer1.ViewReport

Obviously, you would iterate through the available fields and pick out the information you want.

You could also just open up the ttx file as a textstream and read it.
0
 

Author Comment

by:rhubarbtwo
ID: 6326975
Ah this is getting the field info from the data source (rs), I'm wanting to check the names of the fields in the report.

I've setup a merge routine with Word where I check the doc for alias field names, replace the aliases in the doc with Word merge field names, and then merge the doc with the data. I was trying to use a similar model with Crystal, however, its obviously going to be different.

I can setup the ttx file with alias names, but then, assuming the report field names can be extracted, can I change the aliases in the report for field names so the merge works.

Also I had a problem with late binding, I've referenced 'CRDataSource 1.0 Type Library' but using 'Set crpApp = CreateObject("CRAXDRT.application")' I get the error 'ActiveX component can't create object'. Also should I use 'Implements CRDataSourceLib.CRDataSource' as decribed in the developer's help?
0
 

Author Comment

by:rhubarbtwo
ID: 6327121
So far I am using the following code:

'Declarations
     Private crpApp As CRAXDRT.Application
     Private crpReport As CRAXDRT.Report
     Private crpDatabase As CRAXDRT.Database
     Private crpTables As CRAXDRT.DatabaseTables
     Private crpTable As CRAXDRT.DatabaseTable
     Private crpField As CRAXDRT.FieldObject
     Private crpSection As CRAXDRT.Section
     Private crpReportObject As Object


'Sub code
     Set crpApp = New CRAXDRT.Application    
     Set crpReport = crpApp.OpenReport(sDocPath)

        Set crpDatabase = crpReport.Database
        Set crpTables = crpDatabase.Tables
        Set crpTable = crpTables.Item(1)
   
For Each crpSection In crpReport.Sections            
       For Each crpReportObject In crpSection.ReportObjects
            If crpReportObject.Kind = crFieldObject Then  
                Set crpField = crpReportObject
                sField = crpField.Name
            End If
       Next crpReportObject          
Next crpSection


But crpField.Name just returns 'Field1', 'Field2', etc
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6327341
No, my code is pulling the information from the REPORT, not the recordset.  When I tested the code, I had NO recordset open and if you dig around in the local variables window, you will find that you can get the .ttx file name, sample data values assigned, etc.

The way I'd approach your merge problem is not by trying to change to report's field names, but rather by changing the ADO recordset field names to match those in the report.  You can dynamically construct your SQL select and include 'as' clauses to name the fields whatever you want.
0
 

Author Comment

by:rhubarbtwo
ID: 6327407
Oh yes, use aliases in the sql.

Or I could use textboxes/labels in the report as say [[FieldAliasName]], search for these, store position and dimension properties and replace with data fields....??

I'll try your code in your first comment on Monday, have a good weekend.

Any more thoughts oon my question at http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=crystal&qid=20158336 (the '= New' works but not the late binding)
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6327589
Let me know - and I left a comment at your other question.
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6336608
Any luck today with this code?

DRRYAN3
0
 

Author Comment

by:rhubarbtwo
ID: 6337768
I'm getting a 'file not found' error for either of the methods CRViewer1.ViewReport and crpReport.ReadRecords even though I set the corect path for the rpt in the OpenReport method.

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6337898
Did you move the TTX file from its original location?  You cannot do that - one of the problems of using TTX files.
0
 

Author Comment

by:rhubarbtwo
ID: 6339568
That's useful to know. The cause was that I had manually edited the ttx file adding a field through Notepad.

I'm wanting to write a ttx file using code and then add it to reports manually through Crystal...should beno problem with that should there.
0
 

Author Comment

by:rhubarbtwo
ID: 6339586
Still got a problem: The report shows but it only shows the sample data in the ttx file, it doesn't show the data in the adoRS.
0
 

Author Comment

by:rhubarbtwo
ID: 6340368
I've made the following declarations:

Public adoCon As New ADODB.Connection
Public adoRS As New ADODB.Recordset
Public crpApp As CRAXDRT.Application
Public crpReport As CRAXDRT.Report

I've opened an ado con and an ado rs then....

    Set crpApp = New CRAXDRT.Application
    'Set crpReport = New CRAXDRT.Report
    Set crpReport = crpApp.OpenReport(sDocPath)
    crpReport.Database.Tables(1).SetDataSource adoRS, 3
   
    With Form1
        .CRViewer1.ReportSource = crpReport
        .CRViewer1.ViewReport
        .Show
    End With

But all I get in the report is the one line of sample data
0
 

Author Comment

by:rhubarbtwo
ID: 6340374
also:

    Dim sDocPath As String
   
    sDocPath = App.Path & "\report1.rpt"
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6340640
Thanks for the points.

You never get to see data in the rs during design time when using ttx files, only the sample data.  You also need to remove the comment from the set crpReport = new CRAXDRT.Report line and change that line to match my declaration above.
0
 

Author Comment

by:rhubarbtwo
ID: 6340869
If I remove the comment from set crpReport = new CRAXDRT then it causes an illegal op and crashes. If I don't set it to new the rpt opens but only shows the sample data....theis is at runtime.
0
 

Author Comment

by:rhubarbtwo
ID: 6340888
For more points would you have a simple sample app which works?
0
 

Author Comment

by:rhubarbtwo
ID: 6341033
A sample on Planet Source Code uses a Crystal Designer instead of a CRAXDRT.Report. For some reason I can get this sample to display in the viewer with my rpt which is linked to a ttx, but not using the above code.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now