During the process of designing a report template, you might need to provide some specific formatting for a field not based on its position in the report, but instead based on the type of field it is. For example, a company might require that all date/time fields be displayed in military time regardless of operating system defaults. For example, "6:02 p.m. on March 31, 2004" would have to look like "3/31/04 18:02". Another requirement could be a space as the thousand separator for all numbers (instead of the usual comma).
These requirements could easily be corporate or industry standard requirements, such as the ISO 9000 standard. At the time the template is created, it's unknown where these fields will be located in the report or how many of them there will be. You would have to find another way of handling special formatting requirements. Template Field Objects help in this endeavor.
When designing a report specifically as a template, Template Field Objects take the place of regular database fields in a report. They can be placed anywhere that a database field would normally be placed.
These fields are a special type of formula field that contain no data but allow formats to be applied to them as if they were of any data type. Template Field Objects have a special dialog associated with them that exposes all the Formatting tabs of the Format Editor regardless of type. This provides a one-stop shop for all of your formatting needs regardless of the data type for a given position of a field in a report.
The best way to explain this is by actually performing it, so let's implement the examples given previously in this section:
Starting with a new report, follow these steps:
Figure 14.4. The Design tab with the first template object added to the report.
Figure 14.5. The Design tab with six template objects added to the report.
Figure 14.6. The Date and Time tab of the Format Editor with Military Date/Time selected.
Figure 14.7. The Custom Style dialog box with the space set as the Thousand Separator symbol.
Figure 14.8. The Report Title set to describe the Template report.
Figure 14.9. The Preview tab showing how the report looked when the original report was created.
Figure 14.10. The Template Expert dialog box with a template selected.
Figure 14.11. The Preview tab showing how the report looked after the template was applied.
Undoing a template is always an option. If for some reason you do not like the look that the applied template has given to your report, just return to the Template Expert and choose the Undo command at the bottom of the dialog box. Selecting this option and then clicking OK lets Crystal Reports revert to the original report before the template was applied.
Crystal Reports accomplishes this by opening up the temporary backup .rpt that it saved before applying the template file.
Notice that there was no need to know where the date and numeric fields were located in the report because the Template Field Objects were all formatted to handle the different requirements for the different fields. Using Template Field Objects along with the other template tips mentioned in the chapter will make report design quick and easy.
During the previous exercise, you might have noticed that the intended template did not show a preview picture on the right of the dialog window. This can be caused by one of two situations. The Save Preview Picture option in the Document Properties dialog box was not selected. If that option had been checked and the thumbnail still did not appear, it is because the template report was not saved with a Preview.
In the example that you just completed, the template report was not previewed before the report was saved.
Preview Pictures, or thumbnails as they are commonly called, are just thatpictures of the Preview of the report. If a report has not been previewed, it will not have the thumbnail to save.
Another key point to notice on Preview Pictures is that if changes are made in the design of the template and then a save is done, the changes will not be reflected in the thumbnail because the Preview tab was not updated with the changes.
Preview Pictures are very useful in the Template Expert because these images provide you with a visualization of what the template does to the existing report. To save them as a default with all reports, select the Save Preview Picture option in File, Options under the Reporting tab.
Preview Pictures are also important to have if the reports will be delivered through Crystal Enterprise because the Web Desktop application uses the thumbnails as a way to show reports in the front-end.