?
Solved

Accessing Report Field Collection

Posted on 2001-07-27
17
Medium Priority
?
464 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 6
17 Comments
 
LVL 12

Accepted Solution

by:
DRRYAN3 earned 240 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
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
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
 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

765 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