How to change the reportsource on a CRViewer control

Posted on 2006-05-17
Last Modified: 2008-02-01
Hi all,

I have a CRViewer control on a form which also has a tree control.
The tree control lists the titles of the reports the user may want to see in the viewer.
When the user clicks on the tree the first time, the report is displayed fine, using the code below.

When the user again clicks on the tree (2nd and subsequent times), all that is shown is a white background.
Also, after a few clicks, errors start appearing.

It seems that the viewer is unable to refresh its reportsource properly.
Here is a (condensed) snippet of the existing code

    rfn = {The filename of the report to load}
    Set rpt = crxApp.OpenReport(App.Path & "\Reports\" & rfn)
    rpt.Database.LogOnServer "p2sodbc.dll", "Webserver", "webserver", "username", "password"
    With frmReports.crv
       .ReportSource = rpt
    End With

Any suggestions as to how to make this work consistently?
Question by:ajmac-b
    LVL 7

    Expert Comment

    What versions are you using for CR, your App (appears to be VB) and what tree control are you using?  Also, is this a web app (assuming) or Windows?

    Author Comment

    Thanks for you reply
    CR V 8.5
    VB6 SP5
    Not a web app and using the TList control from BennetTec software

    The only way I have been able to do this is to unload and load the form, to force the CRViewer control to be instantiated each time. This is fine when no other form is visible, but ugly when there are, as the other form flashes on while the unload/load cycle takes place.

    I'm wondering, I guess, how to initialise the CRViewer control each time.
    LVL 7

    Accepted Solution

    Sorry, I am not familiar with that 3rd party tree control - so I have no idea how it works.  Also, I have not used VB 6 and CR 8.5 in many years so I can't assist you immediately.  However, I think the main thing you need to do is to test that you are able to grab the 'rfn' and that it 'refreshes' before you set the rpt (your 2nd line of code) ...  What happens when you step through the code, when the first report node works and the second doesn't?

    It's been a while, but is there an option to refresh the viewer?

    With frmReports.crv
           .ReportSource = rpt
        End With

    Author Comment

    The refresh method fails - and causes an error :(

    I have found some other threads that seem to lead to the conclusion that the CRViewer control can't be initialised directly, just on instantiation.
    Also, I have a satisfactory solution in the unloading/loading procedure I outlined above.

    Thanks for your input
    LVL 100

    Expert Comment

    I believe your analysis is correct.  We use a similar nethod and I had to instantiate a new report application each time.  I also had to be sure to remove them from memory


    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
    I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now