Report with parametric query

Top  Previous  Next

Let's design a more complicated report in which the query parameters are requested in a dialogue before the report is created. Use the same project as in the previous section, and click the New Report button in the report designer to clear the old one.


Switch to the “Data” tab and place an “ADO Query” component on the page. Double-click on it to open its editor and enter the following SQL text:


select * from Customer where CustNo > :p1


Add a dialogue form to the report and place a “Label”, an “Edit” and two “Button” components on the dialogue form:




Set the component properties:



Caption = 'Select if CustNo greater than'



Text = '2000'



Caption = 'OK'

ModalResult = mrOk



Caption = 'Cancel'

ModalResult = mrCancel


Open the “Params” property editor of the “Query” component and set the parameter:




After that switch to the report design Page1 and create the report as in the previous example:




When the report is previewed the dialogue prompting for a customer number is displayed. After a figure is entered and the dialogue has been closed with the ОК button the report is created. All customers with CustNos larger than that entered are shown.