I want to be able to add a button to the item card that will cause files external to Navision to print that are related to that item. Imagine a scenario where all files are in:
d:\Pictures
d:\Specs
all files are .jpg in pictures and either .doc or .xls in specs.
The file name ALWAYS matches the code No. off the item card. So if you are on item FM1234 then the files are always FM1234.jpg and FM1234.doc and FM1234.xls.
What would the C/AL Code for the onpush() trigger for the button be to print these files out ?
0
Answers
If you want it automatically print, you will have to use automation for each type of document.
For the different types, if you search the forum, you will find examples for them.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
IF EXISTS('c:\temp\testbook.xls') THEN BEGIN
xlApp.Workbooks.Open('C:\temp\testbook.xls');
xlWorkSheet := xlApp.ActiveSheet;
xlWorkSheet.PrintOut;
END;
Where xlAPP and xlWorkSheet are global variances of type Automation for excel.
HOWEVER if I try the same for Word:
IF EXISTS('c:\temp\testdoc.doc') THEN BEGIN
wdApp.Documents.Open('C:\Temp\testdoc.doc');
wdDoc := wdApp.ActiveDocument;
wdDoc.PrintOut;
END;
OR
IF EXISTS('c:\temp\testdoc.doc') THEN BEGIN
wdApp.Documents.Open FileName:="C:\Temp\testdoc.doc";
wdDoc := wdApp.ActiveDocument;
wdDoc.PrintOut;
END;
NEITHER works. Any idea what the correct Syntax is? wdApp and wdDoc are instances of Automation for word 9.0.
Despite what common sense would make you think, each office application has its own team, so they all have their own ways of doing common tasks. I heard that they are working on streamlining this in the next release of Office though. Big help that is huh
RIS Plus, LLC
How it works exactly I don't know, but there's a Word management codeunit that you could take a look at. wrdApp is an unknown automation server in my locals list, but I'm sure it's something like "Microsoft Word".Application.
RIS Plus, LLC
IF NOT CREATE(wdApp,TRUE) THEN
ERROR(Text001);
There seems to be something wrong with the syntax of the command which ever way I use it. The OPEN command that is.
It tells me Im not using the right parametres when I do it as:
wdApp.Documents.Open FileName:="C:\Temp\testdoc.doc";
Then it tells me it was expecting a variable when I do it as:
wdApp.Documents.Open('C:\Temp\testdoc.doc');
but if I do it by creating a string variable := C:\Temp\testdoc.doc
and then do:
wdApp.Documents.Open(myVar);
The form compiles perfectly, but when I run it and click the button this code is in, it crashes out with a rather long error message for C/AL programmers detailing that C/AL doesnt support this format.
Im baffled and its driving me up the wall. It cant be this easy to get the Excel one to work and this hard for the Word one!!!
RIS Plus, LLC
Ive used the documents.open command exactly like it is in the help file for C/Side reference. I cant see what im doing wrong.
It cant be that hard to simply OPEN a word document
Hope this helps you any further.
For some reason the excel one will let you pass any parametres into it. For example I can set a text variable and use that as the file name. I can use the file name directly. Anything.
But for the WORD one you HAVE to pass all variables in as type text or boolean. You cant pass in FALSE. or 'C:\temp\test.doc'. You cant even set a text constant and use that. You HAVE to create a boolean AND a text variable, set them to what you want and pass THEM in.
A little bit anal if you ask me to restrict it that way, when the excel team didnt, but at least I now have it working.
Thanks all for your time on this!!!
Please update your Topic Title (Let it start with [SOLVED]) so people know you found a solution.
Thanks for posting the solution, that'll be helpful to a lot of folks.
RIS Plus, LLC