locked
How to use CrystalReports with Visual Basic Express Edition

    Question

  • hi,

    I would like to ask a question that is it possble to use crystal reports with visual basic 2005 express edition? if so how?

     

    Thursday, April 13, 2006 12:46 PM

Answers

  • I don't believe so. You will need VS2005 Professional to use Crystal Reports. You may be able to purchase Crystal Reports separately and get it to work with express (I doubt it though), but I think VS2005 Pro will be cheaper.

    Thursday, April 13, 2006 1:19 PM

All replies

  • I don't believe so. You will need VS2005 Professional to use Crystal Reports. You may be able to purchase Crystal Reports separately and get it to work with express (I doubt it though), but I think VS2005 Pro will be cheaper.

    Thursday, April 13, 2006 1:19 PM
  • The good news:  You can use crystal reports with Visual Basic Express

     

    The Bad news:  There are serious limitations with what you can do!!!!

     

    The details: 

    I am writting an app that creates monthly reports of sales for all customers of a specific type.  I basically runs in batch and spits out a pdf format of a report showing the details for each customers monthly transactions, yearly totals, contanct info etc.  Although I havent finished yet I can create the reports I want with out too much difficulty.  BUT I cant seem to view the reports in a "CrystalReportViewer" object while the program is running and I am assuming this is because CR CAN NOT INTEGRATE with Visual Studio Express as it does with Visual Studio.

    To be able to create reports and then save, export, print or view (by first exporting to pdf then viewing pdf file) this is what I have done -

    Crystal reports does not ship with Visual Studio Express as it does with Visual Studio so you will obviously have to buy the full product from Business Objects which is not all a bad thing because there is more functionality than the Crystal Reports.Net bundled with Visual Studio.

    Now according to Business Objects: in order to use the full version of cystal reports with Visual Studio (they do not mention Express so I assume this actually only refers to Visual Studio but might be important, - I did it and it works) you will need to install Crystal Reports XI Release 2.  It is basically Crystal Reports 11 (XI) but is adapted to work with .Net 2.0 ie Visual Studio 2005.  Its verison number should be 11.5.(something) as apposed to CR XI which is version 11.0 or something close.

     

    Use CR XI R2 to create reports as standard then add the relevant crystal  references to your VB express solution:

    crystaldecisions.crystalreports.engine

    crystaldecisions.reportsource

    crystaldecisions.shared

    crystaldecisions.windows.forms

     

    add your report file to your project and then use the "report object model" (see crystal reference for info) to create a reprt object, load your report, format it, select data to display, export or print or whatever.  Just remember that you cant view it in the crystal report viewer on your windows form or at least I havent been able to figure it out yet.

    Here is some code:

    'Declarations

    Imports CrystalDecisions.CrystalReports.Engine

    Imports CrystalDecisions.Shared

     

    'In Class

    Dim customerReport As ReportDocument

    customerReport = New ReportDocument()

    Dim reportPath As String = Application.StartupPath & "\" & "CustMonthly.rpt"   ' I saved my report in the "\BIN\Debug" dir

    customerReport.Load(reportPath)

    Dim strPath As String

    Dim strFileName As String

    'Filename made up of customer number, year, month

    strFileName = strCust & "_" & intYear.ToString & "_" & intMonthStart.ToString

     'Path to save pdf report to and filename saved as

    strPath = Application.StartupPath & "\reports\" & strFileName & ".pdf"

    customerReport.ExportToDisk(ExportFormatType.PortableDocFormat, strPath)

     

     

    Viola - you have a report in pdf

     

    Now to select or filter data I change the RecordSelectionFormula as so: (You can also use parameters, dataviews/datatables etc)

    customerReport.RecordSelectionFormula = "(({customer.Cust_Number} = '" & strCust & "' AND {auditall.Year} = " & intYear & ") AND ({auditall.Month} >= " & intMonthStart & " and {auditall.Month} <= " & intMonthEnd & ")) "

    This selects records matching strCust, intYear, and in month range defined between intMonthStart and intMonthEnd.

     

    For subreport data filtering etc ("YTD" is name of subreport.)

    customerReport.Subreports("YTD").RecordSelectionFormula = "( {customer.Cust_Number} = '" & strCust & "' AND ({auditall.Period} < 200611 and {auditall.Period} >= 200511 ) )"

     

    I must say that the fact that you cant use a crystal report viewer in my windows forms is really upsetting me but luckily in my case the reports are going to be emailed or printed/faxed from the pdf files so it should work out ok (No jinxes here!)

     

    FYI - I am not a serious developer and am pretty knew to Visual Studio Express and Crystal XI. Last developed Visual Studio.Net and intergrated Crystal in 2002!  I know my solution is not pretty but it is working for my needs.  Hope that helps some people who have been stumped like I have been for way to long.

    Monday, November 06, 2006 9:36 AM