Results 1 to 3 of 3

Thread: Method 'ReportSource' of object 'ICrystalReportViewer10' failed.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    Method 'ReportSource' of object 'ICrystalReportViewer10' failed.

    Hello all.
    I'm trying to display a CRX report using the ActiveX report viewer. I call up the report via this code:
    Code:
    Option Explicit
    Private m_sSourceFile As String
    Private m_sSelectionFormula As String
    
    'The SourceFile property should be passed as JUST the beginning of the filename. The rest will be derived by VB. In other words,
    '"HPNotes" or "Smear".
    Public Property Get SourceFile() As String
    
        SourceFile = m_sSourceFile
    
    End Property
    
    Public Property Let SourceFile(ByVal sSourceFile As String)
    
        'Trim the extension off the end if it's there
        sSourceFile = Replace(sSourceFile, ".rpt", "", , , vbTextCompare)
        'If 'Not US', then
        If notUS = True Then
            sSourceFile = sSourceFile & "NL"
        End If
        sSourceFile = sSourceFile & ".rpt"
        m_sSourceFile = sSourceFile
        RenderReport
        
    
    End Property
    
    Public Property Get SelectionFormula() As String
    
        SelectionFormula = m_sSelectionFormula
    
    End Property
    
    Public Property Let SelectionFormula(ByVal sSelectionFormula As String)
    
        m_sSelectionFormula = sSelectionFormula
        RenderReport
    End Property
    
    Private Sub RenderReport()
    'The Crystal reports "application" to hold the report and control the viewer
    Dim vl_CRApp_cra As CRAXDRT.Application
    'The Crystal reports "report" containing the report itself and any changes
    Dim vl_CRRep_cra As CRAXDRT.report
    
    
    'Initialize objects
    Set vl_CRApp_cra = New CRAXDRT.Application
    Set vl_CRRep_cra = New CRAXDRT.report
    
    
    'Ensure that parameters are entered and file exists
    If (SourceFile <> vbNullString) And (SelectionFormula <> vbNullString) And (StrComp(Dir(SourceFile), SourceFile, vbTextCompare) = 0) Then
        
        'Open the report
        Set vl_CRRep_cra = vl_CRApp_cra.OpenReport(SourceFile)
        
        vl_CRRep_cra.RecordSelectionFormula = SelectionFormula
        
        'Set the selection formula on the report
        report.ReportSource = vl_CRRep_cra
        
        RefreshReport
    End If
    
    Set vl_CRApp_cra = Nothing
    Set vl_CRRep_cra = Nothing
    
    End Sub
    
    Private Sub cmdExit_Click()
    Unload Me
    End Sub
    
    Private Sub RefreshReport()
    report.ViewReport
    report.Refresh
    
    End Sub

    Actually, that's all the code for the form. When I call that form from another form, passing the two properties ahead of time, the crystal report displays fine - no problem. But, then I close the crystal report and try to re-open it immediately after and I get the above message.
    I thought that it had something to do with the variables in the crystal report viewer form, but it doesn't. When I hit debug on that error message again, then F5 (to begin execution) it works perfectly.
    I began to think that it was simply working every other time the form was opened, so I get a breakpoint right before the line of code that set the reportsource property. When I hit F5 there, everything works.

    So, ultimately, I need to pause execution of my program then resume it again in order for everything to work. I've tried this with both modal and modeless window modes for both the calling form and crystal report form, but that doesn't seem to help.

    Does anyone have any ideas?

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Method 'ReportSource' of object 'ICrystalReportViewer10' failed.

    Assuming you have posted all the code and the order of events are something like

    frmReport.SourceFile = "C:\Report1.rpt"
    frmReport.SelectionFormula = "{Customer.CustomerId}='WOLZA' "

    cmdExit is clicked

    frmReport.SourceFile = "C:\Report2.rpt"
    frmReport.SelectionFormula = "{Orders.OrderId}=12345"

    The code will try to preview Report2 using Report1's selection formula as soon as the SourceFile property is set the second time. RenderReport is automatically called and the If statement will evaluate to true so Crystal runs the report. But since reports execute asyncronously, the code jumps back to the calling procedure which then sets the SelectionFormula for Report2. RenderReport is automatically called again. The error occurs at this point because the Viewer is still busy trying to load/view Report2 with the first selection formula. Adding a delay gives it time to finish and then the second Selection Formula is applied. However, the second report is being executed twice.

    When you use Unload Me, only the Form's GUI is unloaded. Variables in the Declaration section still retain their values. What the calling procedure would need to do on the second report is

    frmReport.SelectionFormula = vbNullString
    frmReport.SourceFile = "C:\Report2.rpt"
    frmReport.SelectionFormula = "{Orders.OrderId}=12345"

    One option is to clear the property variables in the Form's Unload event. Another is let the calling procedure decide when it is time to Render the report.
    Last edited by brucevde; Feb 5th, 2009 at 03:39 PM.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    Re: Method 'ReportSource' of object 'ICrystalReportViewer10' failed.

    OK. So If I simply clear SelectionFormula and SourceFile on Form_Unload this should clear the CRX info and upon applying new properties CRX won't try to superimpose the selectionformula for the second report when it's meant for the first. Got it. Let me try that and see how it goes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width