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!

Can I open up an individual Crystal Report with VB 2

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
I would like to open up a specific Crystal Report (8.5) from within VB so I can check out some of the properties. Can this be done? I am thinking along the lines of something like the following:

Dim CRO As SomeCrystalReportObject
Set CRO = New SomeCrystalReportObject
CRO.ReportName = path\CrystalReport.rpt

etc

Thanks in advance for any help!

Happy New Year!
 
Make sure you reference the:
Crystal Reports 8.5 Standard Wizard Library
Crystal Report Viewer Control

Make sure you add the component:
Crystal Report Control
add this to the form that is calling the report



CrystalReport1.ReportFileName = App.Path & "\GLReport.rpt"
CrystalReport1.Action = 1
 
Thanks, I set a reference to CR 8.5 Standard Wizard Library and also to the CR Report Viewer Control. How did you dimension and define CrystalReport1 in your example?

Thanks and have a great day!
 

If you want to open a report to look at the inner properties, reference the Crystal Reports 8.5 ActiveX Designer and Run Time Library. You can then use the designer methods to extract what you need:

Dim RptApp As New CRAXDDRT.Application
Dim rpt As New CRAXDDRT.Report
Set rpt = RptApp.OpenReport("c:\myRpt.rpt")
MsgBox rpt.SummaryFields.Count


Mark
 
Mark,

That is exactly what I was looking for! Thanks a ton!

Have a great day!
 
Mark and/or others,

Are there major collections you can spin through in Crystal that are similar to VB collections such as forms, modules, etc.?

Thanks in advance for the help!
 

There are collections within the report object such as Areas, Sections, and Database that are available to inspect and modify. Crystal Decisions does however require a runtime license on some of the runtime APIs that can be called through the designer library. If you use one of these API calls that require a license, a msgbox will advise you of the requirement during run time.

I guess what I'm saying is it depends on what you what your report to do on whether you can modify the collections etc...


Mark
 
Just in case this would help someone else, this is what I have done so far. This has been done by kicking the module into single step mode and manually looking at the various properties.

It would be great if there was a properties or documents collection that I could spin without having to know or care what the actual property names were.

Hope this helps someone! Without the help of this board, I would never have known where to even start, so thanks again!

This code was done in Access97 VBA but I'm pretty sure it would work in VB also.

*************************** CODE ***********************
Option Compare Database
Option Explicit

Public Sub GetCrystalReportProperties(FileName As String)
Dim RptApp As New CRAXDDRT.Application
Dim rpt As New CRAXDDRT.Report

'NOTE: Set reference to Crystal Reports 8.5 ActiveX Designer Design and Runtime Library

Set rpt = RptApp.OpenReport(FileName)
DisplayTablesUsed rpt.Database.Tables
DisplayRptSections rpt.Areas
End Sub

Private Sub DisplayTablesUsed(pcrtTables As DatabaseTables)
Dim craTable As DatabaseTable
For Each craTable In pcrtTables
With craTable
Debug.Print "Table "; .Name
Select Case .DatabaseType
Case crSQLDatabase
Debug.Print Tab(5); "Database Type"; _
Tab(25); "SQL Server"
Case Else
Debug.Print Tab(5); "New DatabaseType"
End Select
Debug.Print Tab(5); "LogOnDatabaseName"; _
Tab(25); .LogOnDatabaseName
Debug.Print Tab(5); "LogOnServerName"; _
Tab(25); .LogOnServerName
Debug.Print Tab(5); "LogOnUserID"; _
Tab(25); .LogOnUserID
Debug.Print
End With
Next craTable
End Sub

Private Sub DisplayRptSections(pcraReportSections As Areas)
Dim craReportSection As Area
For Each craReportSection In pcraReportSections
With craReportSection
Select Case .Kind
Case crReportHeader
Debug.Print "Report Header "; .Name
Case crPageHeader
Debug.Print "Page Header "; .Name
Case crDetail
Debug.Print "Detail"; .Name
Case crReportFooter
Debug.Print "Report Footer"; .Name
Case crPageFooter
Debug.Print "Page Footer"; .Name
Case Else
Debug.Print "New Crystal Report"
End Select
Debug.Print Tab(5); "HideForDrillDown"; _
Tab(25); .HideForDrillDown
Debug.Print Tab(5); "KeepTogether"; _
Tab(25); .KeepTogether
Debug.Print Tab(5); "NewPageBefore"; _
Tab(25); .NewPageBefore
Debug.Print Tab(5); "NewPageAfter"; _
Tab(25); .NewPageAfter
Debug.Print Tab(5); "Suppress"; _
Tab(25); .Suppress
Debug.Print
End With
Next craReportSection
End Sub

****************************** END CODE *****************
 
We are working on something similar, opening and running a load of reports from some VBA code in Excel.....

The problem that we have, is that we verify the database on every print, and when some reports run, we ge the alert, "database has changed" etc etc... but this halts our code....

Is there anyway to prevent alerts in runtime?.... we are using CRAXDDRT

 
I think in verifying the database on every print you are instructing Crystal to do what it can to adapt the report and inform you of any changes that can't be corrected that directly affect the report (such as a field used in the report is no longer in the database.)

I think your options would be not to verify on every print and/or provide the report a recordset through the SetDataSource method that will always match the required fields of the report.






Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top