Samples | Walkthroughs | OutputFormat Strings

See Also ActiveReports for .NET Web 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:
    • Change the name to gfCustomerID
    • Change the ColumnLayout property to False
    • Change KeepTogether property to True
  4. Change the KeepTogether property for the group header and group footer to True.  Change the NewPage property of the group footer to After.
  5. Add the following controls to the PageHeader section:

     

    Control Name Text/Caption Location
    Picture imgLogo (Empty string) 4, 0
    Label lblNorthWind NorthWind 5, 0.0625
    Label lblTraders Traders 5, 0.4375

     

     

  6. Add the following controls to the GroupHeader section:

     

    Control DataField Name Text/Caption Misc Details Location
    RichText (Empty string) rtf (Empty string) (Empty string) 0, 0
    Textbox Subtotal txtTotalOrders (Empty string) Visible = False

    OutputFormat = Currency

    SummaryType = SubTotal

    SummaryGroup = ghCustomerID

    5.437, 0.0625
    Label (Empty string) lblOrderID Order ID (Empty string) 0.875, 2.25
    Label (Empty string) lblOrderDate Order Date (Empty string) 1.875, 2.25
    Label (Empty string) lblAmount Amount (Empty string) 4.375, 2.25

     

     

  7. Add the following controls to the Detail section:

     

    Control DataField Name Text/Caption Misc Details Location
    Textbox OrderID txtOrderID Order ID Align: right 0.8125, 0
    Textbox OrderDate txtOrderDate Order Date OutputFormat = Long Date 1.875, 0
    Textbox Subtotal txtSubtotal Subtotal OutputFormat = Currency

    Align: right

    4.3125, 0

     

     

  8. Add the following controls to the GroupFooter section:

     

    Control Name Text/Caption Location
    Label lblYours Yours, 0.1875, 0.125
    Label lblNTAP Accounts Receivable 0.1875, 0.4375

     

     

  9. Add the following controls to the PageFooter section:

     

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

     

     

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
    • AddressLine
    • 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. Your RichText control should be arranged like the following.

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 © 2005 Data Dynamics, Ltd. All rights reserved.