Glossary Item Box

Samples | Walkthroughs | OutputFormat Strings

See Also ActiveReports for .NET 2 Online Help Send feedback to Data Dynamics

Walkthrough: Rich Text and Field Merging

ActiveReports supports field merged reports using the RichText control. The RichText control can contain field placeholders that are replaceable with their values (merged) at run time.

This walkthrough illustrates how to create a mail-merge report using the RichText control.

This walkthrough is split up into the following activities:

To complete the walkthrough, you must have access to the NorthWind database (NWind.mdb).

When you complete this walkthrough, you will have a report that looks similar to the following:

Adding an ActiveReport to the Visual Studio project

To add an ActiveReport to your project

  1. Open a new project in Visual Studio.
  2. Click on Project > Add New Item.
  3. Select ActiveReports file and rename the file rptLetter.
  4. Click Open.

Connecting the report to a data source

To connect the report to a data source

  1. Click on the yellow report DataSource icon in the Detail section. This brings up the report DataSource dialog box.
  2. Click on Build...
  3. Select Microsoft Jet 4.0 OLE DB Provider and click Next >>
  4. Click on the ellipsis to browse for the access path to NWind.mdb. Click Open once you have selected the appropriate access path.
  5. Click OK to continue.
  6. In the Query field, type "SELECT
    Customers.CustomerID, Customers.CompanyName,
    Customers.ContactName, Customers.Address,
    Customers.City, Customers.Region, Customers.Country, Customers.PostalCode, Orders.OrderID, Orders.OrderDate, [Order Subtotals].Subtotal
    FROM Customers INNER JOIN ([Order Subtotals] INNER JOIN Orders ON [Order Subtotals].OrderID = Orders.OrderID) ON Customers.CustomerID = Orders.CustomerID".
  7. Click OK to return to the report design surface.

Adding controls to the report to contain data

To add controls to the report

  1. Add a GroupHeader/Footer section to rptLetter. 
  2. Make the following changes to the group header:
    • Change the name to ghCustomerID
    • Change the DataField property to CustomerID
    • Change the ColumnLayout property to False
    • Change KeepTogether property to True
  3. Make the following changes to the group footer:
  4. Add the following controls to the PageHeader section:

    Control Name Text Misc Details Location
    Picture imgLogo (Empty string) Image = Logo 4, 0
    Label lblNorthWind NorthWind Font Size = 14 5, 0
    Label lblTraders Traders Font Size = 14 5, 0.25

  5. Add the following controls to the GroupHeader section:

    Control DataField Name Text Misc Details Location
    RichText (Empty string) rtf (Empty string)

    Size = 6, 2.25 in

    0, 0
    Textbox Subtotal txtTotalOrders (Empty string) Visible = False
    SummaryType = SubTotal
    SummaryGroup = ghCustomerID
    5, 0
    Label (Empty string) lblOrderID Order ID

    BackColor = Black
    ForeColor = White

    0.875, 2.25
    Label (Empty string) lblOrderDate Order Date

    BackColor = Black
    ForeColor = White

    1.875, 2.25
    Label (Empty string) lblAmount Amount

    BackColor = Black
    ForeColor = White

    4.375, 2.25

  6. Add the following controls to the Detail section:

    Control DataField Name Text Misc Details Location
    Textbox OrderID txtOrderID Order ID Align: right 0.875, 0
    Textbox OrderDate txtOrderDate Order Date OutputFormat = MMMM d, yyyy 1.875, 0
    Textbox Subtotal txtSubtotal Subtotal OutputFormat = Currency

    Align: right

    4.375, 0

  7. Add the following controls to the GroupFooter section:

    Control Name Text Location
    Label lblYours Yours, 0, 0
    Label lblAR Accounts Receivable 0, 0.5

  8. Add the following controls to the PageFooter section:

    Control Name Text Location
    Label lblNWAddress NorthWind Traders, One Portals Way, Twin Points WA 98156 0, 0

Adding fields to the RichText control

To add fields to the RichText control

  1. Double-click inside the RichText control box to select it.
  2. Right-click inside the box and choose Insert Field.
  3. Insert the following fields in the following order:
    • Date
    • CompanyName
    • ContactName
    • Address
    • City
    • Region
    • Country
    • PostalCode
    • ContactName
    • TotalOrders
  4. Add the following text to the RichText control box: "Dear [!ContactName], Thank you for your business. Below is a list of your orders for the past year with a total of [!TotalOrders]. Please take this opportunity to review each order and total for accuracy. Call us at 1-800-DNT-CALL with any questions or concerns.
  5. Arrange your RichText control like the following example.

Using the FetchData event to get information from the data source

To write the code in Visual Basic

To write the code in C#

Adding code to update the field values in the Rich Text control

To write the code in Visual Basic

To write the code in C#

Adding code to the Group Header BeforePrint Event

To write the code in Visual Basic

To write the code in C#

Viewing the report

To view the report

  1. Add the ActiveReports viewer control to a Windows Form.
  2. Add the code needed to set the viewer document equal to the report document. See Using the ActiveReports WinForm Viewer for help.

Samples | Walkthroughs | OutputFormat Strings

 

 


Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.