can anybody tell me the code of how to call a crystal report from visual basic?
pols help
Who is Participating?
ChaseZeroConnect With a Mentor Commented:
Yeah i know what u mean,

to call the actual file (eg Report.rpt) that was generated in VB all u have to do is

CrystalReport1.ReportFileName = "c:\report\filename.rpt"

so u can change that for different reports.... obviously the report must be configured to read the correct database and layout must be designed first.

to run the report in a preview window see the example code below

   Dim result As Integer
   CrystalReport.ReportFileName = c:\Reports\PatientWeekly.rpt"
' here would be crptToPrinter if u wanted to print it
   CrystalReport.Destination = crptToWindow
   result = CrystalReport.PrintReport
   If result <> 0 Then
      MsgBox "Print Error, Error Number = " & result
   End If

at the end if there is an error the user would be notified...

This is a simple code off the top of my head, it can be more complicated than that with more errorhandling routines
keithtbeAuthor Commented:
Adjusted points to 50
Éric MoreauSenior .Net ConsultantCommented:
This is a procedure that will help you print CR report from VB:

Public Sub PrintCRReport(ByVal pstrReportFile As String, _
                          Optional ByVal pstrCriteria As Variant, _
                          Optional ByVal pbytDestination As Byte = 0)
Dim intResult As Integer

    With fMainForm.CrystalReport1
        If Not IsMissing(pstrCriteria) Then
            .SelectionFormula = pstrCriteria
        End If

        .WindowState = crptMaximized
        .ReportFileName = App.path & "\" & pstrReportFile
        .Destination = pbytDestination
        .WindowTitle = App.Title & " - " & pstrReportFile
        intResult = .PrintReport
        If intResult <> 0 Then
            MsgBox "Error occured." & _
                   vbCrLf & .LastErrorNumber & ": " & .LastErrorString, _
                   vbCritical + vbOKOnly, _
                   "Print error"
        End If
    End With
End Sub
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

keithtbeAuthor Commented:
what i want is to call the report that i generate in the crystal report and then view it in the visual basic
i hope that u can help me tp write the code to call the report from crystal report inside the visual basic
i hope that u know what i mean and help me
thanks alot
Éric MoreauSenior .Net ConsultantCommented:
>what i want is to call the report that i generate in the crystal report and then view it in the visual basic

Depending on the version you are using, maybe you won't be able to see it IN vb. You need the version 6 or higher with the CR viewer in order to make your report sited on your form. See
keithtbeAuthor Commented:
thanks alot
i wil try and see
No probs.


keithtbeAuthor Commented:
another question
how can i ah set decimal point?
i mean when there is a text box that let people key in data
and how can i fixed the decimal point ?
another one
can u pls tell me ahhhhhhhhhhh
i want to fix that only number to key inside the text box and not text
so how to write the code?
and vice versa
thanks alot
All Courses

From novice to tech pro — start learning today.