Create Word Template

IvonaK
Member Posts: 115
Hi to all,
I'm trying to create a word template for every "Item Service Group" . Here is the code:
SalesShipmentLineTemp.RESET;
IF SalesShipmentLineTemp.FINDSET THEN
REPEAT
Item.GET(SalesShipmentLineTemp."No.");
IF ServiceItemGroup.GET(Item."Service Item Group") THEN ;
ServiceItemGroup.TESTFIELD(ServiceItemGroup."Warranty File");
CREATE(wdApp,FALSE,TRUE);
TemplateName:='C:\Warranty\Customers\';
TemplateName:=TemplateName+ServiceItemGroup."Warranty File";
wdDoc:=wdApp.Documents.Add(TemplateName);
wdApp.ActiveDocument.Fields.Update;
ItemDescription:=DELCHR(Item.Description+','+Item."No.",'<',' ');
wdRange := wdApp.ActiveDocument.Fields.Item(1).Result;
wdRange.Text := ItemDescription;
BrendCode:='';
IF DefaultDim.GET(27,SalesShipmentLineTemp."No.",'AD') THEN
BrendCode:=DefaultDim."Dimension Value Code";
wdRange:=wdApp.ActiveDocument.Fields.Item(2).Result;
wdRange.Text:=BrendCode;
wdRange:=wdApp.ActiveDocument.Fields.Item(3).Result;
wdRange.Text:=SalesShipmentLineTemp.Description;
wdRange:=wdApp.ActiveDocument.Fields.Item(4).Result;
wdRange.Text:=SalesShipHdr."Ship-to Name";
ServiceItemGroup.GET(Item."Service Item Group");
wdRange:=wdApp.ActiveDocument.Fields.Item(5).Result;
wdRange.Text:=COPYSTR(FORMAT(ServiceItemGroup."Default Warranty Duration"),1,STRLEN(FORMAT(ServiceItemGroup."Default Warranty Duration"))-1);
wdApp.Visible:=TRUE;
CLEAR(wdApp);
UNTIL SalesShipmentLineTemp.NEXT=0;
I just get the first word doc, and after that I got this error:
"Call was rejected by callee. (Exception from HRESULT: 0x80010001(RPC_E_CALL_REJECTED))."
Any advice,
Thanks a lot,
I'm trying to create a word template for every "Item Service Group" . Here is the code:
SalesShipmentLineTemp.RESET;
IF SalesShipmentLineTemp.FINDSET THEN
REPEAT
Item.GET(SalesShipmentLineTemp."No.");
IF ServiceItemGroup.GET(Item."Service Item Group") THEN ;
ServiceItemGroup.TESTFIELD(ServiceItemGroup."Warranty File");
CREATE(wdApp,FALSE,TRUE);
TemplateName:='C:\Warranty\Customers\';
TemplateName:=TemplateName+ServiceItemGroup."Warranty File";
wdDoc:=wdApp.Documents.Add(TemplateName);
wdApp.ActiveDocument.Fields.Update;
ItemDescription:=DELCHR(Item.Description+','+Item."No.",'<',' ');
wdRange := wdApp.ActiveDocument.Fields.Item(1).Result;
wdRange.Text := ItemDescription;
BrendCode:='';
IF DefaultDim.GET(27,SalesShipmentLineTemp."No.",'AD') THEN
BrendCode:=DefaultDim."Dimension Value Code";
wdRange:=wdApp.ActiveDocument.Fields.Item(2).Result;
wdRange.Text:=BrendCode;
wdRange:=wdApp.ActiveDocument.Fields.Item(3).Result;
wdRange.Text:=SalesShipmentLineTemp.Description;
wdRange:=wdApp.ActiveDocument.Fields.Item(4).Result;
wdRange.Text:=SalesShipHdr."Ship-to Name";
ServiceItemGroup.GET(Item."Service Item Group");
wdRange:=wdApp.ActiveDocument.Fields.Item(5).Result;
wdRange.Text:=COPYSTR(FORMAT(ServiceItemGroup."Default Warranty Duration"),1,STRLEN(FORMAT(ServiceItemGroup."Default Warranty Duration"))-1);
wdApp.Visible:=TRUE;
CLEAR(wdApp);
UNTIL SalesShipmentLineTemp.NEXT=0;
I just get the first word doc, and after that I got this error:
"Call was rejected by callee. (Exception from HRESULT: 0x80010001(RPC_E_CALL_REJECTED))."
Any advice,
Thanks a lot,
0
Answers
-
Few things may be wrong:
Your word file may be in use. If you create a new file with same name it will solve the error. It may be because the file takes too long to open or something is corrupt. If this does not work, try adding SLEEP(Duration) to give it time to open but this is a long shot
Or it may be because you are not using licensed Word.Hope it helps
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K 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
- 320 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