Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Crystal Reports in VB - Error loading report, loads then terminates?

Posted on 2003-03-19
4
Medium Priority
?
564 Views
Last Modified: 2012-05-04
I have a crystal report.  The report views fine inside of crystal.  When loaded from VB it loads than immediatly terminates.  Why would this happen? Following is the code I'm using to call the report.

invoicenumber = Key
SwedishDatabaseLocation = path to database

        CR1.ParameterFields(0) = "invoicenumber;" & invoicenumber & ";True;"
        CR1.DataFiles(0) = SwedishDatabaseLocation
        CR1.ReportFileName = App.Path & "\creport1.rpt"
        CR1.PrintReport

Thanks,
Adam
0
Comment
Question by:adamkushner
4 Comments
 

Expert Comment

by:spiral
ID: 8166821
u will need a form to contain the crystal report let's call it CRViewer

then u must assign the report datasource to the crystal report viewer control on that form CRViewer than
what u r doing now.

CR1.printreport just sent the crystal report to the printer i think. if u want to view your report u need the CRViewer with the crystal report control on it.

i hope you understand me. :)
0
 

Author Comment

by:adamkushner
ID: 8166915
No, a Crystal Report Control will load the report into a Crystal Default window like a VB Report does.

0
 
LVL 4

Expert Comment

by:trkcorp
ID: 8167775
Crystal will generate errors that are not reported as run time errors and in order to determine the problem place an error trap after the printreport command to determine the cause for this failure:
CR1.PrintReport
If CR1.LastErrorNumber > 0 Then _
  MsgBox CR1.LastErrorNumber & " " & CR1.LastErrorString & _
    vbCrLf & "  This error is occurring during print attempt.", vbOKOnly + vbCritical, "Report Error"
0
 
LVL 2

Accepted Solution

by:
selim007 earned 400 total points
ID: 8168403
Dear,
place in a form the crystal report viewer control and the common dialog control and then, insert the code that follow.
P.S. Code is retrieved from the Crystal Sample Source Codes.


Private Sub cmdOpen_Click()
' Set Cancel to True
CommonDialog1.CancelError = True

On Error GoTo errhandler

' Filter the Open dialog box to display
' Crystal Reports files only.
CommonDialog1.Filter = OpenDialogFilter

' Display the open dialog box
CommonDialog1.ShowOpen

' Set the report object to nothing
Set m_Report = Nothing

' Open the selected report
Set m_Report = m_Application.OpenReport(CommonDialog1.FileName, 1)

' Call the procedure to set the report to the Embeddable Designer
' and the Crystal Report Viewer
Call DisplayReport

Exit Sub

errhandler:
Select Case Err.Number
Case 32755
    'User cancelled dialog
Case Else
    errString = "Error # " & CStr(Err.Number) & " " & Err.Description
    errTitle = Err.Source
    MsgBox errString, vbCritical, errTitle
End Select
End Sub

Public Sub DisplayReport()
On Error GoTo errhandler
' Enable the tab control if disabled.
If SSTab1.Enabled = False Then SSTab1.Enabled = True

' Set the Report Object
CRDesignerCtrl1.ReportObject = m_Report
 
' Note----------------
' Set all other properties for CRDesignerCtrl1 after setting the
' ReportObject property
' --------------------
 
' Disable the Help menu
CRDesignerCtrl1.EnableHelp = False

' Set the report source
CRViewer1.ReportSource = m_Report

' Set the zoom level to fit the page width to the
' viewer window
CRViewer1.Zoom 1

' Set the viewer to view the report
CRViewer1.ViewReport

Exit Sub
errhandler:
    errString = "Error # " & CStr(Err.Number) & " " & Err.Description
    errTitle = Err.Source
    MsgBox errString, vbCritical, errTitle
End Sub

thx
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question