Word Automation Error

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); wdApp.ActiveDocument.Fields.Update; //<<<-Error on this line // Set Date wdRange := wdApp.ActiveDocument.Fields.Item(1).Result; wdRange.Text := FORMAT(TODAY,0,’ <Day,2>, '); wdApp.Visible := TRUE; wdApp.ActiveDocument.Fields.Unlink; Bill Benefiel Manager of Information Systems Overhead Door Company billb@ohdindy.com (317) 842-7444 ext 117 Edited by - wbenefiel on 2001 Apr 30 17:33:21

I think I remember that we had a discussion about exactly the same question about half a year ago. Either here or at www.mynavision.net. As I don’t work with word-automation I dont’ recall the answer (think it has to do with “.Fields.Update” which fails in a document without fields) but I’m not sure. So I recommend you do a search in the archive. ------- With best regards from Switzerland Marcus Fabian

You better use variables for each object level, this might help. For Example: create(wdApp); … wdDocuments := wdApp.Documents; wdDocument := wdDocuments.Add(template); wdFields := WdDocument.Fields; wdFields.Update; … In some cases Navision is getting in trouble with early and late binding. Marco — — knk Systemlösungen GmbH — Marco Eymer (meymer@knk.de) — Dipl. Wirtschaftsinformatiker — Beseler Allee 67 fon: 0431/57972-0 — 24105 Kiel fax: 0431/57972-99 —

Taking your suggestion, I modified my code to be: CREATE(wdApp); wdApp.Visible := TRUE; wdDocs := wdApp.Documents; wdDoc := wdDocs.Add(TemplateName); ← Error actually occurs here wdFields := wdDoc.Fields; wdFields.Update; After making the the wdApp visible, I saw the proper document load. I then got the same message I have been getting: Invalid Assignment. It is not possible to assign a_Document to a Document. Help please, this is making me crazy. Bill Benefiel Manager of Information Systems Overhead Door Company billb@ohdindy.com (317) 842-7444 ext 117

Which version of Word are you using? With W2k, the following is ok on my pc: template := ‘c:\temp\fax.dot’; CREATE(wdApp); wdApp.Visible := FALSE; wdDoc := wdApp.Documents.Add(template);

Try in this way: wdDoc := wdApp.Documents.AddOld(TemplateName) Ilaria

Thanks to the last to responders. However, the code that worked for you did not work for me. I am still receiving the same error. Also Documents.AddOld is not a valid command. At least not on my system. By the way, I am running Navision v 2.6 and Office 97. Bill Benefiel Manager of Information Systems Overhead Door Company billb@ohdindy.com (317) 842-7444 ext 117 Edited by - wbenefiel on 2001 May 11 22:19:19