Tutorial 9-3. Unlinked Company Header
Let’s create an unlinked subreport that displays the company address in the report header. You might be tempted to think that it is easier to just type in the company address manually rather than going through the effort of adding a subreport. But there are benefits to using a subreport here. The first benefit is if the company changes location then you can simply update the database with the new address and the report gets updated automatically. If you do this for multiple reports, then every report will be updated as well. It’s also useful to pull the company address out of a database when there are multiple divisions within the company. Each division can share the same reports without having to make any changes to the report header.
Let’s modify the report from Tutorial 9-2 and add a subreport which lists the company information.
- Open the report Customer Credits.rpt’ that you created in the last tutorial. Save it as Company Header.rpt so that you have a new copy to work with.
- The subreport is going to go into the report header section, but right now that section is suppressed. We want to make it visible and then create the subreport and place it in the report header.
- Go into design mode and select the menu items Report > Section Expert. Click on the Report Header section and uncheck the Suppress option. Click the OK button to close the dialog box.
- Select the menu options Insert > Subreport. This opens the Insert Subreport dialog box.
- On the Subreport tab, enter a report name of Company Header.
- Click the Report Wizard button to build the report.
- When the Report Wizard opens, select the table Xtreme.mdb.
- Double-click the table Xtreme Info to move it into the Selected Tables list on the right.
- Click the Next button to go to the Fields section.
- Select the fields Xtreme Name, Address, and Logo Color.
- Click the Finish button to close the wizard.
- You are now back at the Insert Subreport dialog box. Normally, you would click on the Links tab and set the fields that link the report together. But since this is an unlinked report, we are going to skip the Links tab altogether.
- Click the OK button to close the Insert Subreport dialog box.
- You are returned to design mode of the main report so that you can place the subreport object. Move it to the Report Header and click the mouse button to place it there.
- The initial design of the subreport that Crystal Reports created isn’t even close to what we want. So we have a lot of cleanup to do. The goal being to have the address on the left side and having the company logo on the right side.
- Double-click on the Company Header subreport object to open it in design mode. We want to delete everything on the report except what is in the Details section.
- Delete all objects in the Report Header section. Then resize it so that it doesn’t use any space.
- Resize both report footers so that they don’t use any space either.
- We want to put the company logo on the right side of the report. Drag the field Logo Color from the Field Explorer window into the Details section and place it along the right side. Crystal Reports will automatically resize the Details section to make it large enough to fit the company logo image. Delete the field heading that Crystal Reports automatically added when you dropped the logo onto the report.
- We want the company name and address to be listed on the left side of the report with the fields going down the left edge, but they are locked onto the guideline on the left side of the report. Right-click on the guideline and select Remove all Horizontal Guidelines. This releases the fields from the guidelines.
- Move the field Xtreme Name to the top left of the Details section. Place the Address field directly below it.
- The one thing missing from the report is the city and state info. We want these fields to be shown adjacent to each other so we are going to add a text object and insert the fields into the text object. This automatically concatenates the fields next to each other.
- Select the menu items Insert > Text Object. Use the cursor to draw the text object below the Address field.
- Drag the following fields onto the text object: City, Province and Postal Code. They should be adjacent to each other.
- 21. To insure proper punctuation, insert a comma between the City and Province fields. Insert a space between the Province and Postal Code fields.
- We are now finished formatting the Company Header subreport. You’ve done a lot of steps, so review the following figure to check your subreport for accuracy.
- Preview the main report and you’ll see the Company Header subreport displayed at the top of the first page. It should look similar to the following figure. If the report looks good, save the report to keep your changes.