All DataPA reports have scripts behind them that can be used to control the behaviour of the report when it is rendered. The script is useful to define behaviour that is impossible or difficult to achieve with the report designer interface. The syntax of the script must be Windows Scripting VBScript format. For more details on the syntax of VBScript, see Windows Script 5.6 Documentation.
See opening the script editor, using the script editor, objects, events, referring to objects and referring to data.
|
Opening the script editor
|
|
To open the Script Editor, select View-->Open Script Editor from the main menu whilst in design mode.
|
|
Using the script editor
|
The script editor allows to to enter scripting that is executed when particular events are fired for objects in the report. For instance, the code in the example alongside is executed before each instance of the detail section is rendered to the report, and changes the colour of the text based on a value.
To enter script against a particular event, select the object in the Object drop down list, then select the appropriate event in the Events list.
|
|
Objects
|
Object
|
Description
|
ActiveReports Document
|
There is a single active reports object in each report. This object refers to the report itself, and has related events that can be used to modify properties or behaviour for the whole report.
|
Section
|
There is a section object for each section of the report. The section events allow you to modify behaviour or properties for each instance of the section.
|
|
Events
|
Event
|
Object
|
Description
|
OnDataInitialize
|
Report
|
Event fired before ReportStart to add custom fields to report fields collection. In a DataPA report, the recordset is opened and the recordset fields are added to the custom Fields collection then the DataInitialize event is fired so that new custom fields can be added.
|
OnReportStart
|
Report
|
Occurs before a report starts processing.
|
OnReportEnd
|
Report
|
Occurs when report finishes processing
|
OnPageStart
|
Report
|
During the report's processing, this even occurs before each page is rendered.
|
OnPageEnd
|
Report
|
Occurs after each page in the report is rendered.
|
OnHyperLink
|
Report
|
This event fires when a hyperlink is clicked. It can be used to redirect a hyperlink or prevent the link from activating. (NB drill down reports use hyperlinks, so be aware you may effect the behavior of drill down reports).
|
OnFetchData
|
Report
|
Event is fired every time a new record is processed and before any section is rendered. Use to set the values of custom fields that were added in the Data Initialize event.
|
OnNoData
|
Report
|
Occurs when the reports recordset is empty. There is no data to be processed.
|
OnPrintProgress
|
Report
|
Fired for each page during a print job.
|
OnError
|
Report
|
Occurs as the result of a DataPA Reports error or scripting error.
|
OnFormat
|
Section
|
Fired after the data is loaded and bound to the fields, but before the section is laid out for printing. You can use this event to modify the layout of the section or any of the controls on it. This is the only event in which you can modify the height of the section.
|
OnBeforePrint
|
Section
|
Fired before the section is rendered, you can use this event to modify the values of the controls before they are printed. Any changes that are made here will not affect the height of the section.
|
OnAfterPrint
|
Section
|
Fired after the section is. You can use this event to update any counters that you need to use after the section is rendered.
|
|
Referencing Object
|
Reports can be referenced in the script using the identifier Rpt. Each report has a sections collection that contains each section on that report. Each section on a report has a controls collection that contains every object in the section. As such, the syntax to reference a control in a report is:
Rpt.Sections.item("<SectionName>").Controls.item("<ControlName>")
Where <SectionName> is the name of the section and <ControlName> is the name of the control as referenced in the Property Toolbox.
|
Referencing Data
|
Reports can be referenced in the script using the identifier Rpt. Each report has a fields collection that contains the value of each field on the report when referenced. As such, the syntax to reference a field value in a report is:
Rpt.Fields.Item("<FieldName>")
Where <FieldName> is the name of the field.
|