Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Capturing individual mail merge letters

edited January 2002 in General
Hi,

I have the standard setup for mail merge, with a TppRichText control in a
detail band, and one detail band per record. If I code an event handler for
the TppBand's AfterGenerate event, and retrieve TppRichText.RichText at that
point, the data I get has the names of the fields in it, not the merged data
from the database.

We'd like to save off the text of the letters individually, partly for
auditing, partly for other future reference. Anybody found a way to do
that?

Mike Carroll
mcarroll@gosigma.com

Comments

  • edited January 2002
    You can pull the info straight off of the draw command. Use the
    RichText.OnDrawCommandCreate event. Since you'll have multiple ones, you'll
    want to build the destination filename dynamically.

    uses
    ppDrwCmd;

    procedure Tfrm0028.ppRichText1DrawCommandCreate(Sender, aDrawCommand:
    TObject);
    begin


    TppDrawRichText(aDrawCommand).RichTextStream.SaveToFile('C:\mailmerge.rtf');

    end;


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited January 2002
    TppRichText has a property DrawRichEdit of type TCustomRichEdit. This
    property is protected, but it's possible to gain access to it by subclassing
    TppRichText. When the AfterGenerate event fires, the DrawRichEdit property
    contains the data that has been merged from the database record, in place of
    the field names. But it does not seem to contain the RTF formatting
    information, for some reason I haven't figured out yet. So it's possible to
    save the contents of DrawRichEdit in AfterGenerate; it contains the correct
    data but not formatted properly. This may be adequate for some purposes.

    Mike Carroll
    mcarroll@gosigma.com
  • edited January 2002

This discussion has been closed.