Results 1 to 3 of 3

Thread: Crystal reports and VB

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    303
    This is a dumb question, but I would appreciate
    if someone can explain.

    I know Crystal Reports is a reporting tools, but
    how does it work with VB, and where can I find code sample (simple one)?


  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Its kind of its own deal because the reports are stored as rpt files and I think it makes a seperate connection to the database, but it can be called from VB. I have only used the eval version and the old Report component that had more free design tools. The actual report making is alot like Access. You can even run a wizard from Access or Excel to make reports and then call them from VB. but basically when you can the datareport object through the CRViewer that takes care of the coding. just disect the sample if you have downloaded it.

  3. #3
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    Cristal does make its own connection to the database. The way I do this is to create a form template with the CRViewer control on it.

    Ensure the references are set in the Project menu for any project that uses this form:

    Cristal Report Viewer Control
    Cristal Report 8 ActiveX Designer Run Time Library

    (the 8 is version 8 that we use, you may have a different version)

    Create a new form and place the CRViewer control on it and paste the following code on the form:

    Code:
    Option Explicit
    
    Dim Appl As CRAXDRT.Application
    Dim Report As New CRAXDRT.Report
    
    ' holds the report file path
    Private mRepFile As String
    
    Private Sub Form_Load()
       Set Appl = New CRAXDRT.Application
        Set Report = Appl.OpenReport(mRepFile)
        Report.DiscardSavedData
        Report.Database.Tables(1).SetLogOnInfo <database>, , <UserID>, <password>
        
        CRViewer1.ReportSource = Report
        CRViewer1.ViewReport
        
        CRViewer1.Top = 0
        CRViewer1.Left = 0
    End Sub
    
    Private Sub Form_Resize()
    ' keeps the CRViewer the same size as the form
        CRViewer1.Width = Me.ScaleWidth
        CRViewer1.Height = Me.ScaleHeight
    End Sub
    
    '  Property to allow the report path to be passed in
    Property Let ReportFile(rep As String)
        mRepFile = rep
    End Property
    
    Private Sub Form_Unload(Cancel As Integer)
        Set Appl = Nothing
        Set Report = Nothing
    End Sub
    Now you have a reusable form, for any developer to use and for any program.
    You can add more porperties to allow the passing in of the security info (userid,password)
    Then when you want to display a report include the form (and references) in your project then place the following code on the calling form:

    Code:
    Private Sub mnuOutstanding_Click()
        frmReportView.ReportFile = App.Path & "\Students.rpt"
        frmReportView.Caption = "Crystal Report Viewer [Students.rpt]"
        frmReportView.Show vbModal
        frmReportView.ReportFile = ""
        Set frmReportView = Nothing
    End Sub
    if you have more questions email me or post another question. I will try to help if possible.
    good luck


    Things I do when I am bored: DotNetable

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