Creating a Crystal Reports
within Microsoft Visual Basic

 

by Granville Stewart 9-30-2007

 
   

If you need to create reports based upon the data in your database. Then one way of doing so is through Crystal Reports from within the Microsoft Visual Basic Program. Below are step by step instructions on creating crystal reports. You can download the stand alone Crystal ReportsXI program from the official Business Objects site, the company which produces Crystal Reports. The steps are pretty much the same across all versions of Crystal Reports.

 
   
For now, begin by starting Microsoft Visual Basic. Select File/New Project/ Select CRYSTAL REPORT ( See Crystal Report Figure 1)  
   
Crystal Report Figure 1 - File / New Project - Select Crystal Report.
 
Select As a Blank Document - this will create a blank report - noooooo really? After you understand the mechanics of report creation - you can go ahead and use Using the Report Expert. Like you really need my permission.  
Crystal Report Figure 2 - Select As a Blank Report  
   
After you select as a blank report, you will get this page below. This is the default view ( Figure 3). Notice the Database Fields in the Field Explorer on the left side of the screen. Below Database Fields is Formula Fields, Parameter Fields, Group Name Fields, Running Total Fields, Special Fields and Unbound Fields.  
Crystal Report Figure 3 - Right Click Database Fields to select the database.  
   
Right Click on Database Fields / select Database Expert - What this does is attach a database to your Crystal Reports. The most important Folder is the OCBC(RDO) - Clicking on this will give you a series of Databases you can attach to. Select the database you have on your computer. Move the fields you want on your crystal report over by clicking the arrow keys - the field that will appear on your report are shown in the Selected Tables window.(Figure4)  
Crystal Report Figure 4 - Click ODBC(RDO) To Add or Remove Database and Select Tables.  
   
Crystal Report Figure 5 - Select the type of database you have. Usually this will be LocalServer...  
   
Crystal Report Figure 6 - Click On the tables you want Crystal Reports to report on...  
After all that clicking is done from the above - your default page should look like the one below - with the Table and Fields from your chosen database reflected underneath Database Fields.  
   
Crystal Report Figure 7 - See your Database - and selected fields underneath Database Fields.  
   
   
Now it is just a matter of selecting the Fields you want and dragging the Field into the Crystal Reports window. Again. Select the field from under the Database Field - drag it to your right into the Page Header(Section 2) window.  
Crystal Report Figure 8 - Select the fields and drag then into Page Header.  
   
SWITCH TO VISUAL BASIC / SWITCH TO VISUAL BASIC /SWITCH TO VISUAL BASIC
 
   
Now go to or make a blank Visual Studios Form. Select a Crystal Reports Viewer and Drag that into the Blank Visual Studios Form.  
Crystal Report Figure 9 - Open Blank Visual Studios Form - Drag CrystalReportViewer onto the Blank Visual Studios Form.  
   
   
Once you drag the CrystalReportViewer onto a blank Visual Basic Form you can control where the form docks from the properties window ( see below)  
Crystal Report Figure 10 - This is what it should look like. - Visual Basic Form with the CrystalReportViewer on it.  
   
Crystal Report Figure 11 - This is what it should look like. - Visual Basic Form with the CrystalReportViewer on it.  
   
After all the above activity and work - you should have a very nondescript window looking like the one below. Note the above tabs where your Form1.vb ( Blank Form in which you dragged the CrystalReportViewer) and CrystalReport1.rpt (the first part of this tutorial where you selected your Databases and Tables Fields ).

This Application is Blank with no "Data" Source - no "Crystal Report" source - To make this document display all your hard work select from the components - ReportDocument. Drag that into this new blank window. (Below)
 
Crystal Report Figure 12 - Components
/ReportDocument
 
     
To attach the correct report to this blank document select it from the drop down. Think of it this way. you can create many different Crystal Reports - each reporting on a different thing. So this is the way to target your report into the Visual Basic Application.  
 
 
 
 
   
Crystal Report Figure 13 - Choose a Report Document - the one you would have created earlier in this lesson will be listed here.  
   
Your crystal Report "connection string" will appear below - if you want to change the report that is attached to this Visual Basic Form - select on it and change the report. This is called the instance of the crystal reports.  
Crystal Report Figure 14 - below is the instance of your crystal report that is attached to the Form in Visual Studio.  
   
Here is a short cut way on how to tie different crystal reports to your document.  
Crystal Report Figure 15 - In Properties - How to tie different Crystal Reports to the Visual Basic Document.  
   
   
For the next lesson I will explain how to make your Crystal Reports have more detail. We will go back to the Crystal Reports Application. ( We were in Visual Basic above). We will Switch to Crystal Reports to do more things to make your report more detailed.

In the above lesson you learned how to create a simple crystal report - and attach that report to your Visual Basic application. In my next week's lesson ( 10-9-2007) I will show how to create a more detailed Crystal Report.
 
   
Granville Stewart - Author of Article Creating a Crystal Reports
within Microsoft Visual Basic
- is an IT professional in Las Vegas and is a contributor to LVITweb.com
 
If you need to create reports based upon the data in your database. Then one way of doing so is through Crystal Reports from within the Microsoft Visual Basic Program. Above are step by step instructions on creating crystal reports.Based in Las Vegas, Nevada, LVIT gives you a team of IT professionals offering a broad range of computer-related services to an even broader range of clients from Casinos to the small offices environment, we also make house calls, if you find yourself in need of technology HELP we will find a way to serve your needs.  With over 20 years of computer software & hardware experience, we can help you solve all your computer problems.  One call will save you hours of worrying.