Hi everyone! I just talked with some folks at the developer forum about the trouble that I am having with printing a word document from a command button on a form. They suggested me some codes that will enable me doing that, although I followed it, still it didn’t work at all. Here are the information: Local Variables Name DataType Subtype Length MSWordApp Automation ‘Microsoft Word 8.0 Object Library’.Application MSWordDoc Automation ‘Microsoft Word 8.0 Object Library’.Document MSWordDocs Automation ‘Microsoft Word 8.0 Object Library’.Documents Dummy Boolean Readonly Boolean Nomin Record Nomination Codes: // Print out product specifications Nomin.GET(“Entry No.”); IF Nomin.“Doc. Specification Source” <> ‘’ THEN BEGIN CLEAR(MSWordApp); CREATE(MSWordApp,TRUE); MSWordDocs := MSWordApp.Documents; Dummy := FALSE; Readonly := TRUE; MSWordDoc := MSWordDocs.Open(Nomin.“Doc. Specification Source”,Dummy,Readonly); MSWordDoc.PrintOut; MSWordDoc.Close; MSWordApp.Quit; END; The error message that I keep getting is: “This message is for C/AL programmers. Invalid Assignment. It is not possible to assign a_Document to a Document.” I have been trying to figure out what caused this error message the whole day, but still don’t have a clue, and getting very frustrated. Could anybody offer me a big help here? Thanks in advance.
Sylvia, I fail to see any errors in the code you posted. The statements you use to start Word and open the document are the very same ones that work just fine in our system (and they did so with Word 8.0 and 9.0). Did you try and run this code on a different client PC? Did you try and write the same thing in VB (as a Word macro or a stand-alone VB program)? Maybe the Word installation on the PC you get the error on is damaged in some weird way, like corrupted registry entries (which are crucial to the correct working of Automation).
Xorph, Yes, I believe there is nothing wrong with my codes. When you said there might be some problems with the installation of the word on my pc … I think that is possible, and I should try my program on another machine soon. Anyway, I tried this piece of codes yesterday, and it worked: Nomin.GET(“Entry No.”); IF Nomin.“Doc. Specification Source” <> ‘’ THEN BEGIN CLEAR(MSWordApp); CREATE(MSWordApp,TRUE); MSWordApp.Documents.Open(Nomin.“Doc. Specification Source”); MSWordApp.PrintOut; END; Why is that? The very strange thing that I discovered is it will give me the printer icon when printing, but I never could see the name of the document that I will be printing. And somewhat it prints! I really don’t understand this: how much difference between my piece of codes and your piece of codes. Thanks.
Sylvia, if you use the PrintOut method of the Application object, you should specify the file name to print. The Application can have many documents open, and you need to tell it which one to print. If you call this method without any parameters, I assume the result will be unpredictable [:p] If you use the Document.PrintOut method, this tells the document object to print itself, so there’s no ambiguity.
Heinz, I finally got to test the original piece of codes that you agreed it was right on another pc, but I am still getting that error message! So what do you think? I can believe if the registry files of my word application were corrupted at my pc … but not coincidently happened on my coworker’s pc. Any suggestions for my situation?
Sylvia, I’m afraid I’m at my wits’ end on this one [B)] You should try and write a piece of VB code that opens a Word doc and prints it. If this fails, too, then there’s a problem with your Word installation (are the PCs of you and your coworker clones?). If it works in VB, then your Navision installation is broken, or there’s a problem in your C/AL code that is not apparent in the code you posted here. A more trivial reason that just pops up in my mind might be problems with the document you are trying to open. Maybe it’s not a valid Word doc, or it is simply not found (you need to specify the full path), or its permissions are not set correctly. [?]