Using crystal report through vb 6 code

  • 13 years ago

    Can anyone tell me how to use crystal report 9 through vb 6.0 code and how to send data to the report. Any sample code would be much appreciated.


  • 13 years ago

    Since you did not indicate which database engine you are using (DAO, RDO or ADO). But this code will work any of the engine.

    Step 1:  install the CR.

    Step 2: Open the CR to create your report. Create the fields by using CR formular

    Step 3: save the report

    Step 4: Open your program in VB

    Step 5: Add the CR control by going through the menu (Project -> Components)

    Step 6: Create a sub routine that will load the report.

    Step 7: Add this code but you must modified it to your own.

    note: the crtInvided is the name I give to the CR control

       crtInVideo.DataFiles(0) = App.Path & "\InVideo.mdb" ' 
        crtInVideo.ReportFileName = App.Path & "\cdaily.rpt"
        crtInVideo.Formulas(0) = _
            "CompanyName= '" & strCoy & "'"
        crtInVideo.Formulas(1) = _
            "ReportTitle='Cassette/CD Rented Today'"
        crtInVideo.Formulas(2) = _
            "Address= '" & strCoyAddress & "'"
        crtInVideo.Action = 1

    I hope this will useful to you.

  • 13 years ago

    Well I dnt use crystal report in my report but if you want this I'll give it to you..., this code is for DAO if youre using ADO you can simply modify the source of your database

    Hope this would help...

        On Error Resume Next
        Dim de As New DataEnvironment1
        Dim qrydef As QueryDef
        Dim tmprs As Recordset
        Dim str As String
        Set qrydef = dbase.QueryDefs("Employee Masterfile")
        If Err.Number = 3265 Then ' if doesn't exist
            Set qrydef = dbase.CreateQueryDef("Employee Masterfile")
        End If
        Err = 0
        str = "select * from [employee con] where datehired= #" & format(date1,"yyyy") & "#  order by surname asc"
        qrydef.SQL = str
        Set de = New DataEnvironment1

        Set DataReport1.DataSource = de

        DataReport1.DataMember = "cmdMasterfile"

        DataReport1.Show 1
        Err = 0
        Set de = Nothing
        Unload DataEnvironment1


    Employee Masterfile - query made in the database

    cmdMasterfile - command name from the DataEnvironment1

    if you want some sample program just give me your email address...



Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Memory is like an orgasm. It's a lot better if you don't have to fake it.” - Seymour Cray