gregdaly
asked on
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.
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.
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.Applica tion")
oApp.Visible = False
Print:
For i = 1 To LoopCount
strFileName = YourArray(i)
oApp.Documents.Open (strFileName)
oApp.Options.PrintBackgrou nd = True 'worked when false
oApp.ActiveDocument.PrintO ut
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.
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.Applica
oApp.Visible = False
Print:
For i = 1 To LoopCount
strFileName = YourArray(i)
oApp.Documents.Open (strFileName)
oApp.Options.PrintBackgrou
oApp.ActiveDocument.PrintO
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.
ASKER
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).
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
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
ASKER
right. the real issue will be the PDF. I haven't seen any real solutions to that in any postings under other subjects ...
ASKER
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?
I just tried to use the .doc code for an outlook .msg file. It did not work.
Any suggestions for .msg?
ASKER
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....
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....
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.
ASKER
yes tried that initially. it's binary.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Right. I agree. No sense torturing it - I have some ideas for a workaround on the .msg. Thanks for the attention, Arji.
You're welcome. Good luck!
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.Applica
oApp.Visible = False
strFileName = YourArray(i)
oApp.Documents.Open (strFileName)
oApp.Options.PrintBackgrou
oApp.ActiveDocument.PrintO
oApp.Quit
'Clean up code...
Set oApp = Nothing
Next i