navision automation in ms-word

vijaydidmca2003vijaydidmca2003 Member Posts: 27
can any body give me any code, so that i could throw (generate)
navision report in ms-word.

can any body show me how i can use coding for "ms office-word automation" in navision.

i have allready used following coding, but it is showing error.
Name DataType Subtype Length
wrdApp Automation 'Microsoft Word 11.0 Object Library'.Application
wrdDoc Automation 'Microsoft Word 11.0 Object Library'.Document
wrdRange Automation 'Microsoft Word 11.0 Object Library'.Range

Companyinfo.FIND;
userinfo.GET(USERID);

CREATE(wrdApp);
TemplateName:='c:\template.doc';
wrdDoc:=wrdApp.Documents.Add(TemplateName);
wrdApp.ActiveDocument.Fields.Update;

wrdRange:=wrdApp.ActiveDocument.Fields.Item(1).Result;
wrdRange.Text:=USERID;
wrdRange.Bold:=1;

wrdApp.Visible:=TRUE;
wrdApp.ActiveDocument.Fields.Unlink;
when i used above coding i found following error:

"The call to member item failed.the requested member of the collection does not exist."

and the debugger stops at the below given line.Pls give me any solution.thanks.

wrdRange:=wrdApp.ActiveDocument.Fields.Item(1).Result;

regards

vijay tiwari.

Comments

  • SavatageSavatage Member Posts: 7,142
    There's a great example in the Application Designers Guide....
    Here's a sample of how to export nav VENDOR data into word.

    Name DataType Subtype Length
    wdApp Automation 'Microsoft Word 11.0 Object Library'.Application
    wdDoc Automation 'Microsoft Word 11.0 Object Library'.Document
    wdRange Automation 'Microsoft Word 11.0 Object Library'.Range
    TemplateName Text 250
    CREATE(wdApp);
    TemplateName:='c:\"YourWordTemplateNameHere".dot';
    wdDoc := wdApp.Documents.Add(TemplateName);
    wdApp.ActiveDocument.Fields.Update;
    
    wdRange :=wdApp.ActiveDocument.Fields.Item(1).Result;
    wdRange.Text := FORMAT(WORKDATE,0,'<year4>');
    wdRange.Bold :=1;
    wdRange :=wdApp.ActiveDocument.Fields.Item(2).Result;
    wdRange.Text := "No.";
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(3).Result;
    wdRange.Text := Name;
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(4).Result;
    wdRange.Text := Address;
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(5).Result;
    wdRange.Text := "Address 2";
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(6).Result;
    wdRange.Text := City;
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(7).Result;
    wdRange.Text := State;
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(8).Result;
    wdRange.Text := "ZIP Code";
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(9).Result;
    wdRange.Text := "Contact Name";
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(10).Result;
    wdRange.Text := "Vendor Phone No.";
    wdRange.Bold :=0;
    
    wdApp.Visible :=TRUE;
    wdApp.ActiveDocument.Fields.Unlink;
    
    CLEAR(wdApp);
    
  • SavatageSavatage Member Posts: 7,142
    Also if you hve not read the step by step example here's the snipit.
    http://savatage99.googlepages.com/WordA ... romADG.pdf
  • windrebelwindrebel Member Posts: 9
    I have followed these instructions and the doc but I keep getting an error relating to the creation of the file. I even deleted the code and started over thinking that the automation variables were corrupt.

    I get "word was unable to create this document. It may be corrupt.
    Try one or more of the following:
    * open and repair the file.
    * open the file with the text recovery converter.

    I have tried all this has anyone else experienced this problem and been able to get around it?
    Any help would be appreciated since I am still at home plate on this!

    It is obvious that it is not finding the file but I dont know why? All looks correct I have tried both local and network directories.

    I FINALLY GOT IT TO WORK BY RENAMING THE FILE TO FILNAME.DOC not .DOT I dont know why the .DOT (Document template did not work)!
    John F. Maselli
    A Computer Consulting
    www.masellinux.com
  • SavatageSavatage Member Posts: 7,142
    Let's take step back...
    Ok first you followed the ADG steps - correct?
    Does You Automation variable look like what I posted Below?
    Does your PC have Word Installed?
    Did you save your Word Doc as a Template .DOT not .DOC?

    How did the Template creation go for you?
    To create the template:
    1 Open Word and open a new document.
    2 Click Insert, Field and add a field from the Mail Merge category called MergeField.
    3 Enter Contact as the field name.
    The simple template that you are going to use in this example should contain the
    following fields: See Link to ADG
    4 Create these six fields and save the Word document as Discount.dot
  • SavatageSavatage Member Posts: 7,142
    Glad you got it to work.. was the problem this line?
    TemplateName:='c:\"YourWordTemplateNameHere".dot';

    perhaps your code calls for DOC
  • HanenHanen Member Posts: 281
    Hi,

    I'm using MS Word and it works perfectly but now I want to save the word document result as 'c:\MyDoc.docx'
    Is there a save function that I can use????


    Thanks for your Help.
    Regards

    Hanen TALBI
  • FreemanFreeman Member Posts: 28
    Savatage wrote:
    Also if you hve not read the step by step example here's the snipit.
    http://savatage99.googlepages.com/WordA ... romADG.pdf

    Hi.
    I have almost that situation described in quoted link. But I need to print a letters for set of Customers in one Word document. In another words - for each Customer record I have one page in Word document, so if I would like to print 5 records from Customer table, I get 5 pages in Word.

    I need help in modification of this code for creating one Word document for set of records:
    Savatage wrote:
    There's a great example in the Application Designers Guide....
    Here's a sample of how to export nav VENDOR data into word.

    Name DataType Subtype Length
    wdApp Automation 'Microsoft Word 11.0 Object Library'.Application
    wdDoc Automation 'Microsoft Word 11.0 Object Library'.Document
    wdRange Automation 'Microsoft Word 11.0 Object Library'.Range
    TemplateName Text 250
    CREATE(wdApp);
    TemplateName:='c:\"YourWordTemplateNameHere".dot';
    wdDoc := wdApp.Documents.Add(TemplateName);
    wdApp.ActiveDocument.Fields.Update;
    
    wdRange :=wdApp.ActiveDocument.Fields.Item(1).Result;
    wdRange.Text := FORMAT(WORKDATE,0,'<year4>');
    wdRange.Bold :=1;
    wdRange :=wdApp.ActiveDocument.Fields.Item(2).Result;
    wdRange.Text := "No.";
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(3).Result;
    wdRange.Text := Name;
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(4).Result;
    wdRange.Text := Address;
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(5).Result;
    wdRange.Text := "Address 2";
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(6).Result;
    wdRange.Text := City;
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(7).Result;
    wdRange.Text := State;
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(8).Result;
    wdRange.Text := "ZIP Code";
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(9).Result;
    wdRange.Text := "Contact Name";
    wdRange.Bold :=0;
    wdRange :=wdApp.ActiveDocument.Fields.Item(10).Result;
    wdRange.Text := "Vendor Phone No.";
    wdRange.Bold :=0;
    
    wdApp.Visible :=TRUE;
    wdApp.ActiveDocument.Fields.Unlink;
    
    CLEAR(wdApp);
    

    Thanks in advance!
  • FreemanFreeman Member Posts: 28
    Freeman wrote:
    Savatage wrote:
    Also if you hve not read the step by step example here's the snipit.
    http://savatage99.googlepages.com/WordA ... romADG.pdf

    Hi.
    I have almost that situation described in quoted link. But I need to print a letters for set of Customers in one Word document. In another words - for each Customer record I have one page in Word document, so if I would like to print 5 records from Customer table, I get 5 pages in Word.

    I've solved my problem by myself ](*,) ](*,) ](*,)
    If someone interested, here is modified code:
    // Code added
    Vendor.reset;
    Vendor.setrange("No.", '1', '5');
    if Vendor.FINDSET THEN BEGIN
    // --
    
      CREATE(wdApp);
      TemplateName:='c:\"YourWordTemplateNameHere".dot';
      wdDoc := wdApp.Documents.Add(TemplateName);
      wdApp.ActiveDocument.Fields.Update;
    
      // Code added
      wdApp.Selection.WholeStory;  // Select and copy templates lines
      wdApp.Selection.Copy;
      REPEAT
      // --
    
        wdRange :=wdApp.ActiveDocument.Fields.Item(1).Result;
        wdRange.Text := FORMAT(WORKDATE,0,'<year4>');
        wdRange.Bold :=1;
        wdRange :=wdApp.ActiveDocument.Fields.Item(2).Result;
        wdRange.Text := "No.";
        wdRange.Bold :=0;
        wdRange :=wdApp.ActiveDocument.Fields.Item(3).Result;
        wdRange.Text := Name;
        wdRange.Bold :=0;
        wdRange :=wdApp.ActiveDocument.Fields.Item(4).Result;
        wdRange.Text := Address;
        wdRange.Bold :=0;
        wdRange :=wdApp.ActiveDocument.Fields.Item(5).Result;
        wdRange.Text := "Address 2";
        wdRange.Bold :=0;
        wdRange :=wdApp.ActiveDocument.Fields.Item(6).Result;
        wdRange.Text := City;
        wdRange.Bold :=0;
        wdRange :=wdApp.ActiveDocument.Fields.Item(7).Result;
        wdRange.Text := State;
        wdRange.Bold :=0;
        wdRange :=wdApp.ActiveDocument.Fields.Item(8).Result;
        wdRange.Text := "ZIP Code";
        wdRange.Bold :=0;
        wdRange :=wdApp.ActiveDocument.Fields.Item(9).Result;
        wdRange.Text := "Contact Name";
        wdRange.Bold :=0;
        wdRange :=wdApp.ActiveDocument.Fields.Item(10).Result;
        wdRange.Text := "Vendor Phone No.";
        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 Vendor.NEXT = 0;
      // --
    
      wdApp.Visible :=TRUE;
      // Commented wdApp.ActiveDocument.Fields.Unlink;
    
      CLEAR(wdApp);
    END;  // Code added
    
  • HanenHanen Member Posts: 281
    If I want to the same thing but using Excel and each sheet with the vendor code, how can I do it???
    please help, I have to deal with that today or I'll have a serious problem with the customer :(((((((((((((((((((((((((((((((
    Regards

    Hanen TALBI
  • IvonaKIvonaK Member Posts: 115
    I use your code for my Customer list. But when I try to print a document for all Customers it give me a error like picture 5sxgdxbpsnv7.jpg

    It work just for few Customers.

    Any advice.

    Thanks a lot
Sign In or Register to comment.