How to print Word Template for all Customers
IvonaK
Member Posts: 115
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,
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,
0
Answers
-
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
Any advice.
Thanks a lot,
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 326 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions