ActiveReports 6 Online Help
Parameters

You can use the ActiveReports Parameters collection to pass values directly into a textbox or a chart on a report, or to choose what subset of data from your data source to display in a particular instance of a report, or to pass values from a main report into a subreport. There are several ways in which you can collect values for parameters:

There are also several ways in which you can set up parameters for a report:

Collecting Parameter Values

In order to prompt the user for parameter values, all of the following must be in place:

When there are parameters in the collection and the ShowParameterUI property is True, the user prompt automatically displays when the report is run. When the user enters the requested values and clicks the OK button, the report displays using the specified values.

Values of a parameter added to the Report Explorer can be applied to a parameter in the SQL query - you should just specify the "param:" prefix for a parameter in the SQL query. Specifying the "param:" prefix for a parameter in the SQL query relates this parameter to the one in the Report Explorer. For example, "select * from customers where customername = '<%param:Parameter1%>'". In this case, the parameter with the "param:" prefix in the SQL query is updated with values of the corresponding parameter in the Report Explorer.

Tip: Within the same report, you can prompt users for some parameters and not for others by setting the PromptUser property to True on some and False on others.

However, if the report object's ShowParameterUI property is set to False, the user prompt does not display for any parameters regardless of its PromptUser setting.

In order to collect parameters from a main report to pass into a subreport, all of the following must be in place:

To collect parameter values from a Windows form or a Web form, use code to collect the values into variables, and then pass them into the report's ReportStart event. See sample code in the Add Parameters topic. In this case, the report's ShowParameterUI property must be set to False.

Adding Parameters to the Parameters Collection via the SQL Query

When you add a single parameter to a report's Parameters collection via the SQL query, a query that looks like the following creates a user prompt like the one pictured below.

SQL Query.
Copy Code
SELECT * FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID 
WHERE Products.SupplierID = <%SupplierID|Enter a Supplier ID|1|S|True%>

There are five values in the parameter syntax, separated by the pipe character: |

Only the first value (Name) is required, but if you do not specify the third value (DefaultValue), the field list is not populated at design time. You can provide only the Name value and no pipes, or if you wish to provide some, but not all of the values, simply provide pipes with no space between them for the missing values. For example, <%ProductID||||False%>

For a date parameter, you can use a SQL query like the following to allow users to select a beginning and ending date.

SQL Query.
Copy Code
SELECT * FROM Orders INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID 
WHERE OrderDate BETWEEN #<%StartDate|Start date|1/1/1994|D|True%># AND 
#<%EndDate|End date|12/31/1994|D|True%>#

Note: Specifying the "param:" prefix for a parameter in the SQL query relates this parameter to the one in the Report Explorer.

For example, "select * from customers where customername = '<%param:Parameter1%>'".

In this case, the parameter with the "param:" prefix in the SQL query is updated with values of the corresponding parameter in the Report Explorer.

 

See Also

How To