can anybody tell me the code of how to call a crystal report from visual basic?
pols help
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
É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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.