How to print Word Template for all Customers

IvonaKIvonaK Posts: 101Member
Hi to all,

I have to make a word document thet have all Customers. Here is the code:

CREATE(wdApp, FALSE, TRUE);
TemplateName := 'c:\IOS\IOSCustomer.dotx';

Customer.RESET;
IF Customer.FINDFIRST THEN
REPEAT
Customer.CALCFIELDS("Net Change (LCY)");
wdDoc := wdApp.Documents.Add(TemplateName);
wdApp.ActiveDocument.Fields.Update;
wdRange := wdApp.ActiveDocument.Fields.Item(1).Result;
wdRange.Text := Customer.Name;
wdRange := wdApp.ActiveDocument.Fields.Item(2).Result;
wdRange.Text := FORMAT(gdate);
wdRange.Bold := 0;
wdRange := wdApp.ActiveDocument.Fields.Item(3).Result;
wdRange.Text := FORMAT(Customer."Net Change (LCY)", 15, '<Integer Thousand><Decimals,3><Sign,1>');
wdRange.Bold := 1;
wdRange := wdApp.ActiveDocument.Fields.Item(4).Result;
wdRange.Text := Customer.Name;
wdRange.Bold := 0;
UNTIL Customer.NEXT=0;

wdApp.Visible := TRUE;
wdApp.ActiveDocument.Fields.Unlink;

It works, but give me on divided word documents.

Any advice.

Thanks a lot,

Answers

  • IvonaKIvonaK Posts: 101Member
    Hi to all,

    I have resolve this problem with this code:


    Customer.RESET;
    IF Customer.FINDSET THEN
    BEGIN

    CREATE(wdApp,FALSE,TRUE);
    TemplateName := 'c:\IOS\IOSCustomer.dotx';
    wdDoc := wdApp.Documents.Add(TemplateName);
    wdApp.ActiveDocument.Fields.Update;

    // Code added
    wdApp.Selection.WholeStory; // Select and copy templates lines
    wdApp.Selection.Copy;

    REPEAT
    Customer.CALCFIELDS("Net Change (LCY)");

    wdRange := wdApp.ActiveDocument.Fields.Item(1).Result;
    wdRange.Text := Customer.Name;
    wdRange := wdApp.ActiveDocument.Fields.Item(2).Result;
    wdRange.Text := FORMAT(gdate);
    wdRange.Bold := 0;
    wdRange := wdApp.ActiveDocument.Fields.Item(3).Result;
    wdRange.Text := FORMAT(Customer."Net Change (LCY)", 15, '<Integer Thousand><Decimals,3><Sign,1>');
    wdRange.Bold := 1;
    wdRange := wdApp.ActiveDocument.Fields.Item(4).Result;
    wdRange.Text := Customer.Name;
    wdRange.Bold := 0;

    // Code added
    wdApp.ActiveDocument.Fields.Unlink; // Replace all the fields in the first letter
    wdApp.Selection.EndKey; // Go to end of the document

    wdApp.Selection.InsertBreak; // Start new page
    wdApp.Selection.PasteAndFormat(16); // Paste copied template
    UNTIL Customer.NEXT=0;

    wdApp.Visible :=TRUE;
    CLEAR(wdApp);
    END;

    But it works for few customers, if I have a lot of customers I got the error like picture oviv44dv9u2i.jpg

    Any advice.

    Thanks a lot,
Sign In or Register to comment.