@bobnoordam

Category: Crystal reports

Setting the zoom level of a crystal report from code

You can set various default zoom levels for your reportviewer, to control how the report is displayed. Create a form with a crystalreportviewer on it, and set the zoom level to the required value. A zoom level of 1 fits the report to ‘page width’ A zoom level of 2 fits the report to show the full page ‘ — set the viewer properties and bind the report myform.CrystalReportViewer1.DisplayGroupTree = False myform.CrystalReportViewer1.ReportSource = myreport myform.CrystalReportViewer1.Zoom(1) […]

Supressing a group footer based on the number of records in the section

At times you may want to supress a totaling section on your report based on the number of records in the section. In this example, a total for a group is displayed only if there is more then one record in the section. To accomplish this, we need to supress the group footer if there is only one record in the group. For this, we need two things a counter to determine the number of […]

Preventing growing fields from overwriting data lower on the report

Problem : On a crystal reports report, you have a field that can gow quite large, and has ‘can grow’ selected. Hower, when growing it overwrites data lower on the report in the section Solution: Crystal reports fields grow without regard to what’s below it in the same section, you need to create a seperate section for the growing field. Rightclick the report Choose Insert, Section Insert a new detail or pageheader section on the […]

Getting a named day-of-week from a date field

To get a named “day of the week” in your crystal report, do the following: – Create a new formula field, using the editor – Paste the formula below in, replacing with the name of your report field containing the date [“Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saterday”, “Sunday”] [DayOfWeek({<datefield>})]

Creating a PDF from a crystal report at runtime

The code sample below shows how to create a pdf during runtime from any crystal report. This code assumes you already have a valid report ‘myreport’, if you want an example of how to create a report item from code check ‘ — export report to pdf ‘Imports CrystalDecisions.CrystalReports.Engine ‘Imports CrystalDecisions.Shared Dim s_filename As String ‘ name of the file Dim s_serverpath As String ‘ path to store the file Dim exportoptions As ExportOptions Dim […]

Creating a crystal report from an in-memory data table

To use data from an in memory created table object over a direct SQL query has the advantage that you can manipulate the data before it is send to the report, e.a. – you can calculate fields, or remove fields from the dataset before it is passed to the report. Design the report as normal. You can design the report using a direct link to the sql server, or the data set present in visual […]

Binding a string to a textfield on a report at runtime

This sample demonstrates how to display a string in an unbound field on a crystal report. This can be used to display messages which are diffrent depending on runtime parameters during report generation. Private Sub DisplayReport() Dim myreport As ReportDocument Dim freestring As CrystalDecisions.CrystalReports.Engine.TextObject myreport = New ReportDocument myreport.Load() freestring = myreport.ReportDefinition.ReportObjects(“Text1”) freestring.Text = “Your message here” CrystalReportViewer1.ReportSource = myreport End Sub

Compare a string field as a date on a report

This formula can be used to compare a string field in a database against the current date and time on a crystal report. Place the formula in the Selection expert / Details. Rows where the date and time contained in the string field falls before the current date and time will be supressed. Note that it is usualy better to handle this kind of selections server side on de the SQL server, because in this […]