Word Automation Error

wbenefielwbenefiel Member Posts: 12
edited 2001-05-16 in Navision Financials
Please see the code below. Every time the code runs I get the following error:
Invalid assignment. It is not possible to assign a_Documentment to a Document.

Code:

CREATE(wdApp);
TemplateName := 'c:\windows\desktop\SecondDem.dot';
wdDoc := wdApp.Documents.Add(TemplateName); //<<<-Error on this line

wdApp.ActiveDocument.Fields.Update;

Please note that the correct template does open prior to the error.

Bill Benefiel
Manager of Information Systems
Overhead Door Company of Indianapolis
billb@ohdindy.com
Bill Benefiel
NCPS,NCSD
Manager of Information Systems
Overhead Door Company of Indianapolis
billb@ohdindy.com

Comments

  • horriganhorrigan Member Posts: 27
    Hardwiring the template file name like that is a BAD idea. There is no guarantee that the file will always be on the client machine at all (let alone on the desktop), or that the windows directory will be c:\windows. Putting files on the desktop is not a wonderful idea either, although Navision doesn't handle shortcuts very well.

    I reccomend putting the file on a network drive and getting the filespec from one or more fields on some table in Navision (or from a text variable in the codeunit or other object itself.)

    Having said that, I am not sure why your code doesn't work. The template file is NOT being loaded before the problem line: all you did there was load the filespec into a text variable. My guess would be that the filespec is incorrect, and the best way to test for a correct filespec is to use a file variable, assign the appropriate filespec, and then see if Navision can open the file.



    Tim Horrigan, NCSD
    <Horrigan@AOL.com>

    Currently in search of new employment!

    Certified as a Solution Developer and an HR/Payroll Specialist!
    Tim Horrigan, NCSD
    <Horrigan@AOL.com>

    Currently in search of new employment!

    Certified as a Solution Developer and an HR/Payroll Specialist!
  • wbenefielwbenefiel Member Posts: 12
    Tim, I am well aware of the dangers of hard-coding things as well as using the desktop as the place a file is located. You may want to consider the fact that the code I listed was in it's infancy and did NOT represent the way the final product will be. It was for testing only.

    Having said that, your statement listed below was not clear for me. When I make the application visible IT DOES LOAD THE CORRECT document. The problem must exist elsewhere. By the way I am running Financials 2.6 and Office 97.


    The template file is NOT being loaded before the problem line: all you did there was load the filespec into a text variable. My guess would be that the filespec is incorrect, and the best way to test for a correct filespec is to use a file variable, assign the appropriate filespec, and then see if Navision can open the file.


    Bill Benefiel
    Manager of Information Systems
    Overhead Door Company of Indianapolis
    billb@ohdindy.com

    [This message has been edited by wbenefiel (edited 04-05-2001).]
    Bill Benefiel
    NCPS,NCSD
    Manager of Information Systems
    Overhead Door Company of Indianapolis
    billb@ohdindy.com
  • HaZeHaZe Member Posts: 1
    Just use this code:

    wdDoc := wdApp.Documents.AddOld(...);

    and it will work.


    Best regards

    HaZe

    Best regards

    .::HaZe::.
  • wbenefielwbenefiel Member Posts: 12
    When I added the code as you suggested, I got an unknown variable error 'AddOld'.

    I am using Navision 2.6B and Office '97. I also have Visual Studio loaded on my machine.

    Thanks.



    Bill Benefiel
    NCPS,NCSD,NCDS
    Manager of Information Systems
    Overhead Door Company of Indianapolis
    billb@ohdindy.com
    Bill Benefiel
    NCPS,NCSD
    Manager of Information Systems
    Overhead Door Company of Indianapolis
    billb@ohdindy.com
Sign In or Register to comment.