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

Opening Crystal report that is included in Project

Status
Not open for further replies.

M8KWR1

IS-IT--Management
Dec 8, 2008
20
0
0
GB
I've got this code

Dim crReportDocument As New ReportDocument()

crReportDocument.Load()

I have a report in the solution called "company details.rpt"

All i am trying to do is load this, so i can then apply it to the crystal viewer, but can not figure out how to do this.

Can anyone help me please, its driving me crazy!!!

Many thanks
 
Hello,

Here is some code that might help to direct you in another direction. It's abbreviated code that I use to access reports.

Code:
'// Declare the Crystal Application Object that will be used for this application.
Private CR_Application As CRAXDDRT.Application

'// Declare the Crystal Report object that will be used for the MAIN report.
Private CR_Report As CRAXDDRT.Report

'// Declare the Crystal Database, DatabaseTables and DatabaseTable objects.
Private CR_Db As CRAXDDRT.Database
Private CR_DbTables As CRAXDDRT.DatabaseTables
Private CR_DbTable As CRAXDDRT.DatabaseTable

Private Sub Print_Report(pReport As String, pPreview As Boolean)
'// Parameters: 
'//    pReport - the name of the report to be used (Full path required).
'//    pPreview - Determines whether the report is previewed or sent to the printer.

   Dim prn As Printer
   Dim frmQ As Form

   '// The following creates the Application object (which is the Crystal
   '// Automation Server) and assigns it to CrystalApplication.
   '// Creating this object must be done for each application that uses the Crystal Automation Server.
   '// If this is to be related to using the ActiveX or OCX control, this following
   '// method would be thought of as simply placing the control onto the VB form.
   Set CR_Application = New CRAXDDRT.Application
   
   '// The following sets the database location for all tables that are used in the report
   Set CR_Report = CR_Application.OpenReport(pReport, 1)
   Set CR_Db = CR_Report.Database
   Set CR_DbTables = CR_Db.Tables
   Set CR_DbTable = CR_DbTables.Item(1)

...
'(NOTE: I use ttx files and ttx information is placed here)

   CR_Report.SelectPrinter prn.DriverName, prn.DeviceName, prn.Port
   CR_Report.PaperSize = crDefaultPaperSize
   CR_Report.PaperSource = crPRBinAuto

   If pPreview Then
      '// Previews the report on the screen.
      Set frmQ = New frmViewer
      frmQ.Initialize_Report CR_Report, "Report Title"
   Else
      '// Sends the report to the printer
      CR_Report.PrintOut False
   End If
End Sub

I have a another form called 'frmViewer' with one control on it: 'CrystalActiveXReportViewer' with the following:
Code:
Private Sub Form_Load()
'// Set up the form.
   Me.WindowState = vbMaximized
End Sub

Private Sub Form_Resize()
   With caxrViewer
      .Top = Me.ScaleTop
      .Left = Me.ScaleLeft
      .Height = Me.ScaleHeight
      .Width = Me.ScaleWidth
   End With
End Sub

Public Sub Initialize_Report(pReport As CRAXDDRT.Report, pTitle As String)
'// Initialize the form.
   On Error GoTo ERR_Handler
   
   With caxrViewer
      .ReportSource = pReport
      .ViewReport
      .Zoom 100
   End With
   Me.Caption = pTitle
   Me.Show
   Exit Sub
   
ERR_Handler:
   Msgbox(Err.Number, Err.Description, "frmViewer.Initialize_Report"
End Sub

I hope this can help you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top