Walkthrough: Parameters with Simple Reports
In ActiveReports, the Parameters dialog can be used to prompt for user input when reports are generated. If you add "<%FieldName | PromptString | DefaultValue | Type %>" to the report's SQL string, it will cause the Parameters dialog to be displayed.
This walkthrough illustrates the basics of using parameters in simple reports.
The walkthrough is split up into the following activities:
- Adding an ActiveReport to a Visual Studio project
- Connecting the data source to a database
- Adding controls to contain the data
- Viewing the report
To complete the walkthrough, you must have access to the NorthWind database (Nwind.mdb).
When you have finished this walkthrough, you will have a report that looks similar to the following.
Adding an ActiveReport to a Visual Studio project
To add an ActiveReport to your project
- Open a new project in Visual Studio.
- Click on Project > Add New Item.
- Select ActiveReports file and rename the file rptParams.
- Click Open.
Connecting the report to a data source
To connect the report to a data source
- Click on the yellow report DataSource icon in the Detail section. This brings up the report DataSource dialog box.
- Click on Build...
- Select Microsoft Jet 4.0 OLE DB Provider and click Next >>
- Click on the ellipsis to browse for the access path to NWind.mdb. Click Open once you have selected the appropriate access path.
- Click OK to continue.
- In the Query field, type "SELECT * FROM orders INNER JOIN [order details] ON orders.orderid = [order details].orderid WHERE orderdate =#<%Date|Order date:|1/1/1994|D%>#".
- Click OK to return to the report design surface.
Adding controls to the report to contain data
To add controls to the report
- Add a GroupHeader/Footer section to rptParams.
- Make the following changes to the group header:
- Change the name to ghOrders
- Add the following controls to the GroupHeader section:
Control |
Name |
Text/Caption |
Location |
Label |
lblOrderDate |
Order Date |
0, 0 |
Label |
lblShipName |
Ship Name |
1.1875, 0 |
Label |
lblShipAddress |
Ship Address |
3.1875, 0 |
- Add the following controls to the Detail section:
Control |
DataField |
Name |
Text/Caption |
Location |
TextBox |
OrderDate |
txtOrderDate |
Order Date |
0, 0 |
TextBox |
ShipName |
txtShipName |
Ship Name |
1.1875, 0 |
TextBox |
ShipAddress |
txtShipAddress |
Ship Address |
3.1875, 0 |
Viewing the report
To view the report
- Add the ActiveReports viewer control to a Windows Form.
- Add the code needed to set the viewer document equal to the report document. See Using the ActiveReports WinForm Viewer for help.
Samples | Walkthroughs | Parameters
Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.