I have a problem when I ran report from vb6. I use Crystal Report 8.5 as reporting tools and MySql as database for my program. When I tried to run the report in Crystal Report, it worked. But when I ran it from vb6, it showed an error: "Server has not yet been opened". Here is my codes for showing the report. Can anyone help me pliz to find the solution for my problem. Thx before.

Dim formlap1 As New lap_pembelian_barang
        Dim crystal1 As CRAXDRT.Application
        Dim dbTable As CRAXDDRT.DatabaseTable
        Dim Report1 As CRAXDRT.Report           
        Dim SubReport As CRAXDRT.Report
        Dim Sections As CRAXDRT.Sections
        Dim Section As CRAXDRT.Section
        Dim RepObjs As CRAXDRT.ReportObjects
        Dim SubReportObj As CRAXDRT.SubreportObject
        Dim n As Integer
        Dim i As Integer
        Dim j As Integer


        formlap1.CRViewer1.DisplayBorder = False 
        formlap1.CRViewer1.DisplayTabs = False   
        formlap1.CRViewer1.EnableDrillDown = False   
        formlap1.CRViewer1.EnableRefreshButton = False

        Set crystal1 = New CRAXDRT.Application         
        Set Report1 = crystal1.OpenReport(App.Path & "\laporan\pembelian_per_barang.rpt")
        For n = 1 To Report1.Database.Tables.Count
          Report1.Database.Tables(n).SetLogOnInfo "localhost", "database", user, pass
        Next n
       
        Set Sections = Report1.Sections
 
      For n = 1 To Sections.Count 
       Set Section = Sections.Item(n)
       Set RepObjs = Section.ReportObjects
   
              For i = 1 To RepObjs.Count
                 
                 If RepObjs.Item(i).Kind = crSubreportObject Then
                    Set SubReportObj = RepObjs.Item(i)
                    Set SubReport = SubReportObj.OpenSubreport
                   
                      For j = 1 To SubReport.Database.Tables.Count
                        SubReport.Database.Tables(j).SetLogOnInfo "localhost", "database", user, pass
                      Next j
     
                 End If
             
              Next i
       Next n

        Report1.DiscardSavedData               
        Report1.Database.SetDataSource rs       
        Report1.RecordSelectionFormula = "{faktur_pembelian_header.tgl_faktur}>= #" & DTPickerawal.Value & "# and {faktur_pembelian_header.tgl_faktur}<= #" & DTPickerakhir.Value & "#"
        formlap1.CRViewer1.ReportSource = Report1
        formlap1.CRViewer1.ViewReport
        formlap1.Show
        Unload Me

I don't see where you set the cr to the database... Ahh there it is at the bottom. Try putting it higher in your code...

Good Luck

what do you mean by higher? oh..did I should set the cr to the database before setLogOnInfo? I will try it then and give an update later. Thx for your reply. Hope it will work. :)

Hi, I already tried to put my code higher, but it's stil not working. I wonder if it has something to with the connection? I used DNS for data source when I set connection in Crystal Report. But I didn't use DNS in VB. Is it related or not? Ahh..I still can't figure it out. :( Can somebody help me pliz? Is there something wrong with the coding?

hmm..I used DSN that I already created in ODBC (control panel-administrative tools-data sources(ODBC)). So, when I want to connect database with CR, I just picked ODBC DSN I created.

Hmmmm... Ahhh... Hmmm... So it works when using the ODBC DSN in the CR designer but not via the CR control from VB... Hmmm...

Okay, with a search on yahoo for vb6 crystal reports 8.5 tutorial, I get a bunch of junk but on the 3rd page of the search results I found this...

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=65542&lngWId=1

While not a tutorial, the code for the reports should help you in telling you what is wrong with your code...

I'm really surprised that there is not at least an example out there some where...

BTW: there should be some example code for vb on the cr cd...


Good Luck

This article has been dead for over six months. Start a new discussion instead.