Get Crystal Report Viewer Control 8.5 (crviewer.dll) to load external .rpt files

mhall_691984
mhall_691984 used Ask the Experts™
on
Hey there

I am having a hard time trying to figure out how to load in external report files (that reside in a folder on the same computer as the application) into the Crystal Report Viewer ActiveX control. I have seen examples of how to do this in the legacy control thats provided, but I need to use the new crviewer.dll control. Basically I just need to know how to tell my CRViewer object (in VB6) to load "c:\testreport.rpt" and then show it in the control.

I will also need to specify a different query for the report as I need to filter data that appears on the report.

Hope you can help!

Matt.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
I recommend you download this file.  This is a beginner-level application example for calling external reports with VB.

http://support.businessobjects.com/communityCS/FilesAndUpdates/simpledemo.zip.asp

Author

Commented:
This example does not seem to be relavent - I need to load RPT files into my app at runtime! Can this be done?

Commented:
What version of Crystal Reports are you trying to use?  Where did the .RPT files come from, your version or a newer version?  Crystal Reports does not maintain backward file format compatibility.
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Commented:
Yes, this can be done by adding the CR viewer component to your VB project.  You mentioned in the second part of your question making changes though and you aren't going to be able to make changes if all you do is view an external report.





Author

Commented:
I am using Crystal Reports Developer Version 8.5 to create the report files and save them to disk. When I installed developer edition, I got the active X viewer. (CRVIEWER.DLL). Added this to my project and tried embedding the report like sample frodoman pointed me at. This is totally pants in that I cant seem to get the report even working without installing SQL Sever Client Connectivity tools (from the SQL Server 2000 install cd) and also the DSR file retains information about the IP address of the sql server. When the project is moved to the customers site, the IP its looking at is wrong, of course.

I have tried using SetLogonInfo for each table in the Report.Tables() collection, but this does NOT work. I even checked subreports were getting changed to the right IP - and tried removing them.

Therefore, the only, and better way to do this is to get CRVIEWER to swallow its pride and take .RPT files that are not embedded, but located in a folder somewhere. This needs to be done at run time. The does not need to edit the report from within my host application, it should just get the report layout from a RPT file, which we could change at a later date without changing the application binary.

This seems like something that would be supported, I just cant find any methods to do it.

Again, the RPT file needs to be accessed at RUNTIME, and it is NOT embedded into a DSR file and compliled with the app.

Hope you can help guys, thanks for your help so far!

Author

Commented:
Its worth noting again that this is supported in the legacy control they provide, but as mentioned above, i dont want to use this legacy control.

Commented:
Generally I believe you want something like this:

Dim CrxApp As New CRAXDRT.Application
Dim CrxRpt As CRAXDRT.Report

Private Sub Form_Load()
Set CrxRpt = CrxApp.OpenReport(App.Path & "\YOURREPORT.RPT")
CRViewer1.ReportSource = CrxRpt
CRViewer1.ViewReport
...
End Sub

Author

Commented:
This looks more like it frodoman, i'll give it a whirl.

Author

Commented:
Well, this appears to load the report, but its coming up with Server Not Yet Opened! The report is set to use ODBC if that matters..

'SQL-MIS' is the System DSN.

Code:

Dim CrxApp As New CRAXDRT.Application
Dim CrxRpt As CRAXDRT.report

Private Sub Form_Load()
   
    '// load the report up
   
    Set CrxRpt = CrxApp.OpenReport("H:\Source\App\rpt\rptInvoice.rpt")
   
    CRViewer1.ReportSource = CrxRpt
   
    Dim intTableID As Integer
   
    For intTableID = 1 To CrxRpt.Database.Tables.Count
   
        CrxRpt.Database.Tables(intTableID).Set "SQL-MIS", "[R&D_MIS]", "Sa", "------"
       
    Next
    CRViewer1.ViewReport
   
    CrxRpt.SQLQueryString = "SELECT [R&D_MIS].dbo.tbl_system.*, tbl_orders.*, tbl_orderitems.* FROM tbl_orders, tbl_orderitems, tbl_system WHERE (tbl_orders.OrderNo = '" & InputBox("Type order number") & "') AND tbl_system.[ID] = '1' ORDER BY tbl_orderitems.NonStock, tbl_orderitems.DamperFlag, tbl_orderitems.PartNo"
   
    Screen.MousePointer = 11
   
    Do
        DoEvents
    Loop While CRViewer1.IsBusy
   
    CRViewer1.Refresh
    Screen.MousePointer = 0

End Sub
Commented:
This is a common error message.  Business objects provides a doc specifically for trouble-shooting this situation:

http://support.businessobjects.com/library/kbase/articles/c2002649.asp

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial