Results 1 to 5 of 5

Thread: VB code with Crystal Reports

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    High Wycombe, UK
    Posts
    142

    VB code with Crystal Reports

    Hello,

    I am working for a company that writes many Crystal Reports each day. We now have approaching 500. We use Stored Procedures to query the SQL database.

    Occasionaly, but more anf more frequently, we have a problem where the database requires a change such as uppercasing a field to use a bad example. We would like to know how many reports use this field.

    Is it possible to write code in VB that uses the Crystal Objects to determine the Stored Procedure it uses? If a Stored Procedure isn't used then the Command code needs to be evaulated? I can then write some code to search the Stored Procedure code to locate any field matches?

    Anyone done anything like this before or can point me in the right direction?

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: VB code with Crystal Reports

    Yes, you can use the Crystal objects to figure out which stored procedure is used by reports. The following code is for Crystal 8.5, I would assume it is similar with other versions. You need a reference to the Crystal Reports ActiveX Run-Time Library.

    VB Code:
    1. Dim objCrystalApp As CRAXDRT.Application
    2.     Dim objReport As CRAXDRT.Report
    3.  
    4.     Dim objDB  As CRAXDRT.Database
    5.     Dim objTables    As CRAXDRT.DatabaseTables
    6.     Dim objTable     As CRAXDRT.DatabaseTable
    7.    
    8.     Dim objSections  As CRAXDRT.Sections
    9.     Dim objSection As CRAXDRT.Section
    10.    
    11.     Dim objReportObjects As CRAXDRT.ReportObjects
    12.     Dim objSubReports As CRAXDRT.SubreportObject
    13.     Dim objSubReport As CRAXDRT.Report
    14.    
    15.     Dim lngIdx As Long
    16.    
    17.     Set objCrystalApp = New CRAXDRT.Application
    18.     Set objReport = objCrystalApp.OpenReport(ReportFileName, 0)
    19.    
    20.     Set objDB = objReport.Database
    21.     Set objTables = objDB.Tables
    22.        
    23.     For Each objTable In objTables
    24.          Debug.Print objTable.Location 'stored procedure or database table name
    25.     Next
    26.  
    27.     'Check any SubReports in the Main report.
    28.     'Access to Sub Reports is through the Sections collection
    29.  
    30.     Set objSections = objReport.Sections
    31.  
    32.     For Each objSection In objSections
    33.        
    34.         Set objReportObjects = objSection.ReportObjects
    35.        
    36.         If objReportObjects.Count > 0 Then
    37.  
    38.             For lngIdx = 1 To objReportObjects.Count
    39.                 'make sure the report object is a subreport.
    40.                 If objReportObjects(lngIdx).Kind = crSubreportObject Then
    41.  
    42.                     Set objSubReports = objReportObjects(lngIdx)
    43.                     Set objSubReport = objReport.OpenSubreport(objSubReports.SubreportName)
    44.  
    45.                     Set objDB = objSubReport.Database
    46.                     Set objTables = objDB.Tables
    47.  
    48.                     For Each objTable In objTables
    49.                         Debug.Print objTable.Location
    50.                     Next
    51.                 End If
    52.             Next
    53.         End If
    54.     Next

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    High Wycombe, UK
    Posts
    142

    Re: VB code with Crystal Reports

    Thank you very much for your help. This is EXACTLY what I am looking for.

    One quick question. Where you obtain the Stored Procedure name or Database Table, would you get the 'Command' code if that is the method of obtaining the data from within the report?

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: VB code with Crystal Reports

    I am sorry, I don't understand what you mean by 'Command' code.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    High Wycombe, UK
    Posts
    142

    Re: VB code with Crystal Reports

    Hello,

    'Command' Code is an area of the report where you can paste in SQL code directly to execute or your can place EXEC 'SP_NAME' in there instead.

    Don't worry too much about it. You have helped me plenty so far. I have an idea for an mini application that can assist us with our 600+ Crystal reports. I don't have a copy of VB6 so I am trying to convince my boss that getting hold of a copy will result in me being able to solve a problem. Once I can get that then I will work on him to get .net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width