?
Solved

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

Posted on 2003-03-19
4
Medium Priority
?
562 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

770 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