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:

 

clip0273

 

Set the component properties:

 

Label1:

Caption = 'Select if CustNo greater than'

 

Edit1:

Text = '2000'

 

Button1:

Caption = 'OK'

ModalResult = mrOk

 

Button2:

Caption = 'Cancel'

ModalResult = mrCancel

 

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

 

clip0274

 

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

 

clip0275

 

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.

 

clip0276