Repost: Printing file from MS Access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Good afternoon,
I have a few files (one Excel and one PDF) that I would like MS Access to
print out for me without having the application opening up Adobe Acrobat
Reader and MS Excel. (I'd rather use file system commands if possible).

Is there any way to do this without connecting Access to the applications
(and workbook and pdf document)?

Thank you in advance!

Derek
 
What do you mean by "connecting Access to the applications"? Do you mean
adding references? You can do this without adding references through
CreateObject and Late Binding. However, you *cannot* print an .xls file
without starting Excel (at least invisibly). You *cannot* print a .pdf file
without starting Acrobat, at lease invisibly. The instructions for printing
reside in those application. The user need not see it, but the applications
must be present and used.

HTH,

Kevin
 
Thanks, Kevin. Yes, I am meaning adding references. My next question, as
long as I need to use the Acrobat Reader and Excel to do the printing...

How can I do this invisibly as you referenced? Thank you!

Derek
 
Kevin,
Well, I got the invisible printing figured out. More like invisible
applications. Anyway, I'm thinking that I need to reference the PDFlib.
However, I don't know how to actually get the application open. I get an
error message that ActiveX cannot control the object. I'm trying a
CreateObject ("pdf.application") to fire it up.

Any adivce would be appreciated.

Thank you!
Derek
 
Derek,

I guess I jumped the gun. Acrobat Reader cannot be controlled through
automation. Acrobat, however, can. The code at the bottom automates
Acrobat to print. You can automate Excel as well. You don't need to add
references in Access if you use Late Binding. This involves declaring
objects as type Object and using CreateObject or GetObject to get a pointer
to said objects. Using CreateObject and GetObject require knowing the
correct class names. For Excel, you'll use "Excel.Application". For
Acrobat, you'll need "AcroExch.App", "AcroExch.AVDoc", and "AcroExch.PDDoc".

It can be worthwhile to use Early Binding (add a reference to Excel or
Acrobat and declare objects As Excel.Application, etc.) while in development
so that you get Intellisense help with object and can use the Object Browser
(F2) to identify methods and properties. Before I distribute code I like
switch back to Late Binding. I remove the reference and change any
Dim xlApp As Excel.Application

to

Dim xlApp as Object 'Excel.Application

HTH,

Kevin
'******************
Public Sub PrintAcrobatFile(strFile As String)
Dim avdoc As Object 'Acrobat.CAcroAVDoc
Dim pddoc As Object 'Acrobat.CAcroPDDoc
Dim app As Object 'Acrobat.CAcroApp

Dim iPages As Integer ' number of pages in document

On Error Resume Next
Set app = CreateObject("AcroExch.App")
If Err = 429 Then
MsgBox "The full Acrobat Program is not installed. Cannot automate
Acrobat unless it is.", vbOKOnly
Err.Clear
On Error GoTo 0
Exit Sub
End If

Set avdoc = CreateObject("AcroExch.AVDoc")
Set pddoc = CreateObject("AcroExch.PDDoc")

'Show Acrobat if you'd like
'app.Show

pddoc.Open strFile 'Open the file

' count the pages of the document
iPages = pddoc.GetNumPages

'proceed only if the document has pages / is not null
If iPages > 0 Then

Set avdoc = pddoc.openAVDoc(strFile)

'print the 0-based index of pages

avdoc.PrintPages 0, iPages - 1, 1, False, False

avdoc.Close True
End If
pddoc.Close

Set avdoc = Nothing
Set pddoc = Nothing

If Not (app Is Nothing) Then app.Exit
Set app = Nothing

End Sub
 
Thanks, Kevin. I have the AcroBat 7.0 Type Library, and I don't see the
AcroExch that you refer to. So, I guess I cannot control Acrobat. However...

The document that I have in PDF is also available on the web. Still as a
PDF file, but it has a URL. Perhaps I can use Internet Explorer references
to accomplish the same thing...

Does that sound like a possibility to you? What I'm thinking is to open IE
and point it to the URL for my document (it's a standard US government form).
Once it loads, I can print the 'page'...

What do you think?

Thank you!
Derek
 
Good morning, Kevin,
I was able to open the document in IE instead of Acrobat. (yes, that means
I assume the user has Acrobat Reader...)

Anyway, I cannot get the page/PDF to print. Here's my code:

Private Sub cboNewVendor_Click()
Dim IEShellWins As SHDocVw.ShellWindows
Dim IEapp As SHDocVw.InternetExplorer
Set IEShellWins = New SHDocVw.ShellWindows
Set IEapp = CreateObject("InternetExplorer.Application")
IEapp.Visible = True
IEapp.Navigate ("http://www.irs.gov/pub/irs-pdf/fw9.pdf")
?????
End Sub

If you have any advice, I would greatly appreciate it. Thank you in advance!

Thanks!
Derek
 
Back
Top