Word Automation Error

wbenefiel
Member Posts: 12
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
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
NCPS,NCSD
Manager of Information Systems
Overhead Door Company of Indianapolis
billb@ohdindy.com
0
Comments
-
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!0 -
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.com0 -
Just use this code:
wdDoc := wdApp.Documents.AddOld(...);
and it will work.
Best regards
HaZe
Best regards
.::HaZe::.0 -
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.comBill Benefiel
NCPS,NCSD
Manager of Information Systems
Overhead Door Company of Indianapolis
billb@ohdindy.com0
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