Working with reports in your VBA project

To use VBA with a report, you’ll first need to add the report to your project. Adding a report creates a corresponding report object in your project, which you can reference in VBA.

Adding a report object

To add a report to your project, launch Report Writer. Create a new or modified version of the report you want to work with, then display the report’s layout. With the Report Layout window active, choose Add Report To Visual Basic from the Tools menu.

Once you’ve added a report, switch to the Visual Basic Editor and display the Project Explorer. It should look similar to the following:


Although you created a modified report using Report Writer, this was only necessary to access the report’s layout and create the report object in VBA. You can determine whether you want VBA code to run for either the modified or the original version of the report using the report’s EventMode property. See the section titled Using modified or original reports for more information about the EventMode property (report).

Removing a report object

To remove a report object from your project, launch Report Writer and open the report layout for the report you want to remove. From the Tools menu, point to Customize, then choose Remove Current Report From Visual Basic. VBA will remove the report and any report fields associated with the report from your project.

Adding report field objects

You can add two types of report fields to your VBA project: table fields and calculated fields. To add a report field to your project, select the field in the report layout using the arrow tool, then choose Add Fields To Visual Basic from the Tools menu.

If the same field appears multiple times on a report, it’s important that you select the field located in the report section from which you are going to reference the field. For example, a report field may appear in the report body and in the page footer. If you will be referencing the field from the BeforePF event, be sure you’re adding the field located in the page footer.

If the field is not a table field or a calculated field, the Add Fields To Visual Basic menu item will appear disabled. To add several fields at once, hold down the SHIFT key and select the fields, then choose Add Fields To Visual Basic.

After you’ve added a report field to a project, you can reference it only from within a report event procedure. Report fields, unlike window fields, have no associated field events. Therefore, you cannot write VBA code specifically for a report field.

Documentation Feedback