Printing External files from the Item Card

Mauddib
Member Posts: 269
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 ?
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
-
Well, with HYPERLINK, you can open the files automatically, but then you have to manually print it from the application that has opened the document.
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.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
I remember a similar thread: Print files with an associated applicationNo support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0
-
Im getting there. This works for excel:
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.0 -
You can try this from the office VBA editor. From there you get the intellisense dropdown list that shows you the whole object model, and inside you can browse to the print methods.
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.
0 -
The print isnt the problem im having though, its the OPEN part thats not working. IF I get past this stage Im sure ill get the print part working.0
-
You'll need a reference to the Word Application object for the open method to work. I am guessing that in your excel code there is already a CREATE(xlApp) statement, or it works because you happen to already have Excel running.
How it works exactly I don't know, but there's a Word management codeunit that you could take a look at.IF ISCLEAR(wrdApp) THEN CREATE(wrdApp);
wrdApp is an unknown automation server in my locals list, but I'm sure it's something like "Microsoft Word".Application.0 -
Sorry fraid this isnt it either
I already have:
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!!!0 -
There should be some working example in standard Navision, in the wordmanagement codeunit. Have you looked at that at all? I have not worked with this myself, but that's where I would start looking.0
-
Argh no, they dont have anything for simply opening a file.
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 document0 -
In codeunit 5054 WordManagement, function OpenWordAttachment, I notice following line:
wrdDoc := wrdApp.Documents.Open2000(FileName,ParamFalse,Attachment."Read Only");
Hope this helps you any further.No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0 -
Actually this is only serving to confuse me further as open2000 isnt a valid function. If you hit compile while looking at that code unit it wont compile. Weirder and weirder.0
-
AGH ITS SIMPLE!!!!!!
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!!!0 -
Great!
Please update your Topic Title (Let it start with [SOLVED]) so people know you found a solution.No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0 -
Actually I like them to be restrictive. I don't like it when an object model has 2 million ways to do one simple task. It is much easier for me to remember two specific types of variables.
Thanks for posting the solution, that'll be helpful to a lot of folks.0 -
Id have to disagree though, and im sure it would be an interesting debate. But I prefer when theres many ways to get to the same solution. Especially when there are subtle differences. When one solution doesnt work you tweak it. More control, more power, and above all more fun when you are a programmer and you find a new path around a problem to acheive what you want. Restrictive solutions takes half the joy out.0
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