Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

10.24 Re-Mapping Fields

Re-mapping Fields

When replacing one table with another table, it is possible that one or more of the fields on the report won’t have exact matches in the new table. If the fields in a table are renamed or deleted, this affects the existing fields on your report. When this happens, Crystal Reports gives you the option to remap the existing fields to the new fields in the database.

After using the Set Location dialog box or when using the Verify Database function, Crystal Reports checks if any changes have been made to the table. If it detects that a change has occurred that affects fields being used on the report, it opens the Map Fields dialog box shown in Figure 10-17. It shows the fields that don’t have a matching field in the current table. It also shows you the new fields in the data source so that you can match the old fields to the new fields. Crystal replaces them accordingly.



Figure 10-17. The Map Fields dialog box.

This dialog box is only displayed when necessary. If changes are made to fields that aren’t being printed, then it isn’t necessary to re-map these fields. Fields that only had their data types changed are not mapped either, but you should check their output when the report runs to make sure they are formatted properly.

There is no way to open the Map Fields dialog box directly. It only opens in response to another action. For example, you have to open it indirectly by choosing the menu options Verify Database or Set Location, and even then it only opens the dialog box when it finds a problem with the current data source.

The Map Fields dialog box is divided into two halves. The top half shows the unmapped fields. The left-most window shows the fields that are in the report but don’t have a matching field in its assigned table. The right-most window shows all the fields from the currently selected tables. Select one of the unmapped fields in the left window and then select one of the available fields in the right window. Click on the Map button to replace the old field with the new field. You might notice that not all the fields are listed in the right-most window. This is because the checkbox to the right, labeled “Match type,” is checked by default. This requires you to only match fields that have the same data type. It won’t list the fields that don’t have the same data type. If you uncheck this checkbox, all fields are displayed and you can replace a field with a field of a different data type. You should be cautious when mapping different data types and you should preview the report to make sure that the formatting and spacing of the fields are appropriate. The formatting of the old field may not have carried over properly.

If there are fields that are currently mapped, but you still want to replace them with a different field, use the window in the lower half of the dialog box. In the left-most window, click on the field to replace and then click the Unmap button. This moves the field to the Unmapped window in the top half and you can now follow the previous steps to re-map it with a new field.

There are times when you decide to swap out one field for another. Unfortunately, this requires you to delete the original field and possibly lose a lot of formatting. You could try using the Map Fields dialog box to switch them because this won’t lose your formatting, but there isn’t a menu option to open the Map Fields dialog box. You’re in a tough spot.

A new feature in Crystal Reports XI R2 is the ability to swap fields on a report. If you hold down the Shift key before dragging a field from the Field Explorer window, you can drop it onto an existing field on the report and the two fields get swapped with each other. The size, placement and formatting all stay the same. When doing this, a double-arrow will appear above the report to indicate that the fields are about to be swapped. This is shown in Figure 10-18.



Figure 10-18. Swapping a field with an existing report object.

After you accept the mapping changes, the report is automatically updated so that all report fields and formulas have the old field name replaced with the new field name. This saves you the trouble of going back through a report and modifying all formulas that referenced that field. This is the same effect as using a program like MS Word and using the Search and Replace function.