• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 654
  • Last Modified:

Print hyperlinked documents?

I have a form that displays a purchasing requisition.  Each requisition can have 0 to many attached files containing price quotes.  These files are listed as hyperlinks in a list box on the form.  

When I want to print a purchase order (which is a report based on the requisition record) I would also like to print the associated hyperlinked documents.  I don't need to preview the documents - I prefer to send them directly to the printer with the purchase order.

Thanks in advance.
0
gregdaly
Asked:
gregdaly
  • 7
  • 6
1 Solution
 
ArjiCommented:
I use a loop that extracts the filename from an Array I stuffed.  If you know how many filenames you are trying to gather you can assign that number to the varialbe LoopCount.  It's always better to determine the amount programmatically so that the routine is dynamic.  You can iterate through the listbox and collect the document names/paths.

   Dim frm As Form, ctl As Control
   Dim varItm As Variant, LoopCount as Integer

    Set frm = Forms!YourForm
    Set ctl = frm!ListBox
    For Each varItm In ctl.ItemsSelected
        YourArray(varItm) =  ctl.ItemData(varItm)
    Next varItm


Print:
    For i = 1 To LoopCount
        Set oApp = CreateObject("Word.Application")
       
        oApp.Visible = False
        strFileName = YourArray(i)
       
        oApp.Documents.Open (strFileName)
        oApp.Options.PrintBackground = True   'worked when false
        oApp.ActiveDocument.PrintOut
        oApp.Quit
       
        'Clean up code...
        Set oApp = Nothing
    Next i
0
 
ArjiCommented:
Sorry, didn't collect the amount of items selected first:

Dim frm As Form, ctl As Control, YourArray() as string
Dim varItm As Variant, LoopCount as Integer
Dim oApp As Object

LoopCount = 0
    Set frm = Forms!YourForm
    Set ctl = frm!ListBox
    For Each varItm In ctl.ItemsSelected
          LoopCount = LoopCount + 1
    Next varItm

Redim YourArray(LoopCount)

    For Each varItm In ctl.ItemsSelected
        YourArray(varItm) =  ctl.ItemData(varItm)
    Next varItm

Set oApp = CreateObject("Word.Application")
oApp.Visible = False

Print:
    For i = 1 To LoopCount
        strFileName = YourArray(i)
         oApp.Documents.Open (strFileName)
        oApp.Options.PrintBackground = True   'worked when false
        oApp.ActiveDocument.PrintOut
     Next i

'Clean up code...
oApp.Quit
Set oApp = Nothing

Now you can use LoopCount to Dimension the array and then for the loop to print the docs.
0
 
gregdalyAuthor Commented:
Do you have any ideas for how to handle a case where the linked files are not all word documents?  They can be .txt, .pdf, .xls, .doc, .rtf and .msg (that's an exchange message email).
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
ArjiCommented:
I'm believe all the programs you need would have to be installed on the system the code is being executed on. Which is basically Office.  I'm not real versed on Word but I do know it will open .txt, doc, rtf, html files with no problem.  The previous code creates an invisible instance of Word and opens a file and then prints it. You can use a Select Case structure to make the appropriate decisions to print whatever filetype needed based on the value of strFileName.  I'm not versed in printing a .pdf file from Access.  I'm sure someone monitoring this question will know. I would also dim another string variable.

Dim LastThree as string

    For i = 1 To LoopCount
        strFileName = YourArray(i)
             LastThree = Right(strFileName,3)
             Select Case Lcase(LastThree)
               Case = "txt", "doc","rft"
                    'Code to open the document in word
               Case = "xls"
                     'Open instance of Excel, load the file and print it
               Case = "pdf"
                       'Do the 'print the PDF' thing here
             End select
     Next i

0
 
gregdalyAuthor Commented:
right. the real issue will be the PDF.  I haven't seen any real solutions to that in any postings under other subjects ...
0
 
gregdalyAuthor Commented:
excellent.  that takes care of .doc, .txt, .rtf, and .pdf.
I just tried to use the .doc code for an outlook .msg file.  It did not work.
Any suggestions for .msg?
0
 
gregdalyAuthor Commented:
i also tried to use the shellexecute to print the .msg file and that did not work.

addtionally using shell execute to print .htm or .html files requires user interaction in a print dialog box.

Any ideas how to print the .msg file and avoid the print dialog box on htm/l files?

Getting really close to a good solution....
0
 
ArjiCommented:
By chance, have you tried opening a .msg file with Word?  If .msg is purely text then it should open in Word.  If it's a binary file, nothing's going to open it.
0
 
gregdalyAuthor Commented:
yes tried that initially.  it's binary.
0
 
ArjiCommented:
Not sure where to go from here.  Maybe if the .msg file is opened from an instance of Outlook it will allow you to print it.  I'm just not sure that will work because I think .msg is more of an 'internal' file format used to store msgs in a store of some sort, like a .pst file.
0
 
gregdalyAuthor Commented:
Right.  I agree.  No sense torturing it - I have some ideas for a workaround on the .msg.  Thanks for the attention, Arji.
0
 
ArjiCommented:
You're welcome.  Good luck!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now