How to programmatically set the database file for Crystal Report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thesti
    New Member
    • Nov 2007
    • 144

    How to programmatically set the database file for Crystal Report

    How to set the database file (MS. Access db) for a rpt file (Crystal report) programmaticall y in vb6?

    the problem is that, the rpt file is referring to the mdb file using an absolute path. so, when i open the project on another computer/different location, it couldn't file the .mdb file.

    i've encoutered this problem in .NET where we can set the location of the mdb file programmaticall y using the ConnectionInfo class of CrystalDecision s.Shared.

    is there a similar code that can be done from vb 6?

    this is my current code in vb 6 to open and show the report.

    Code:
        Dim rpt As New CRAXDRT.Application
        Dim CRreport As New CRAXDRT.report
        
        'refresh data diCR
        Set CRreport = rpt.OpenReport(App.Path & "\lappenjualan.rpt", 1)
        
        
        CRreport.ReadRecords
        CRreport.DiscardSavedData
                
        report.ReportSource = CRreport
        report.ViewReport

    Thank you.
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    Try this :
    [code=vb]
    Dim crTab As CRAXDRT.Databas eTable
    For Each crtab In CRreport.Databa se
    crTab.Location = "C:\MyDB.md b"
    Next
    [/code]

    Regards
    Veena

    Comment

    • thesti
      New Member
      • Nov 2007
      • 144

      #3
      Originally posted by QVeen72
      Hi,

      Try this :
      [code=vb]
      Dim crTab As CRAXDRT.Databas eTable
      For Each crtab In CRreport.Databa se
      crTab.Location = "C:\MyDB.md b"
      Next
      [/code]

      Regards
      Veena
      hi,

      thx Veena.

      i've tried your it.

      actually it is isn't it?

      Code:
      For Each crtab in CRreport.Database.Tables
      it opens Ms Access three time (because there are 3 tables i used in the report), ask a confirmation to open the database and close again.

      but then an error occurs saying Run-time error 445 "Object doesn't support this action" on line

      Code:
      CRreport.ReadRecords
      i put your suggestion code before the CRreport.ReadRe cords. if i put after the ReadRecords and DiscardSavedDat a, then a messagebox saying "Not Implemented" pops up and the CRViewer shows nothing, just a gray form.


      hmm, maybe something is missing. Thank you

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        yes, you are right.. it should be tables.. and comment the line "Readrecords".. .

        check this code:

        [code=vb]

        Dim rpt As New CRAXDRT.Applica tion
        Dim CRreport As New CRAXDRT.report
        Dim crTab As CRAXDRT.Databas eTable

        Set CRreport = rpt.OpenReport( App.Path & "\lappenjualan. rpt", 1)
        CRreport.Discar dSavedData


        For Each crtab In CRreport.Databa se.Tables
        crTab.Location = "C:\MyDB.md b"
        Next

        MyViewer.Report Source = CRreport
        MyViewer.ViewRe port

        Set rpt =Nothing
        Set CRreport =Nothing
        Set crTab =Nothing

        [/code]

        Regards
        Veena

        Regards
        Veena

        Comment

        Working...