We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Access 2007: Opening a PDF document from a path saved in a table from a command button

Bevos
Bevos asked
on
Medium Priority
281 Views
Last Modified: 2012-05-11
Hello, I have a form that a couple users will work on where they enter some data on pdf documents.  The path of those documents is stored in a field called FiileName.  I want to put a command on the form that uses the table where FileName is stored.
Thus far I've searched through Google and found some code to start, but I can't get it to work.  Could anyone take a look at the code and offer comment, or please direct me toward a better solution?

Thank you so much,
Bevo S.

Private Sub OpenPDF_Click()
Dim AcroApp As Object
Dim PDDoc As Object
Dim avDoc As Object

Set AcroApp = CreateObject("AcroExch.App")
Set PDDoc = CreateObject("AcroExch.PDDoc")

If PDDoc.Open(tblStudyDescription.FileName) Then
AcroApp.show
Set avDoc = PDDoc.OpenAVDoc("")
Else
MsgBox "Unable to open the PDF-file", vbInformation
End If

Set avDoc = Nothing
Set PDDoc = Nothing
Set AcroApp = Nothing
End Sub

Open in new window

Comment
Watch Question

Scott McDaniel (EE MVE )Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
First: you can't refer to a table in that fashion. Are you running this on a Form, and is that form based on tblStudyDescription? If so, then assuming that you have the .pdf file extension associated with the AcroReader, just use Shell:

Shell Me.FileName

Author

Commented:
Hi LSMConsulting, I am running this from a form with tblStudyDescription as the base.  I also have .pdf files associated with the Acrobat Reader.  I tried using the shell command (I've never used it before so I am probably doing so incorrectly) in this fashion:

Private Sub OpenPDF_Click()
Shell Me.FileName
End Sub

The error I receive is the following: 'Run-time error 5: Invalid procedure call or argument'

Sorry for not being more savvy with the VBA and thanks for the help,
Bevo S.
Scott McDaniel (EE MVE )Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Is Me.Filename the FULL path to the PDF file, including the directory?

Author

Commented:
Yes, its stored as such:
C:\Documents and Settings\Bevos\My Documents\Wrede2009.pdf

Author

Commented:
I tried storing it as "C:\Documents and Settings\Bevos\My Documents\Wrede2009.pdf" as well with no luck.  Is there something with the spaces in the directory path that could be causing a problem?
Scott McDaniel (EE MVE )Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Ahhh ... there are spaces in the filename. Try this instead:

Dim sFile As String
sFile = Chr(34) & Me.FileName & Chr(34)
Shell sFile

Chr(34) is the double quote ( " ) so basically this surrounds your filename with double quotes.

Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Wow, that last bit worked great! Thanks so much for taking the time to demonstrate how to use the Shell command!  I have one last question though.  I have been trying to learn a lot of this through trial and error and also some onilne tutorials.  It has been going okay but I think I could use some additional resources.  Are there any webiste you would recommend other than experts-exchange or books on the subject of VBA in access?

Thanks again for all of the help I wouldn't have been able to get it working otherwise,
Bevo S.
Scott McDaniel (EE MVE )Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Any of the WROX books on Access would be good ones, or the Microsoft Press books. It's hard to say without knowing your skill level, but I'd say you're definitely past the beginner stage, so take the time to review the books to insure they're not just a rehash of stuff you already know.

As to sites - EE is probably the best out there, although there are some tutorial sites that provide actual instruction (and the Microsoft Office site has some pretty good stuff as well).

In the long run, however, it's just daily exposure to the product that will get you the most experience. While EE is a great resource, the best thing you can do is make every effort to resovle the problem yourself, before posting here on EE (or anywhere else).

Author

Commented:
Thanks so much again! I'll look into these resources :)
Scott McDaniel (EE MVE )Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Great, but could you please accept the correct response to your question? EE depends on questions being properly answered, and while the comment I made is of value to you, it doesn't really answer your question.

I've asked the Moderators to reopen this so that you can review instead accept one of the other comments as the solution.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.