Link to home
Start Free TrialLog in
Avatar of Bevos
Bevos

asked on

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

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

Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

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

Avatar of Bevos
Bevos

ASKER

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.
Is Me.Filename the FULL path to the PDF file, including the directory?
Avatar of Bevos

ASKER

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

ASKER

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?
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.

ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bevos

ASKER

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.
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).
Avatar of Bevos

ASKER

Thanks so much again! I'll look into these resources :)
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.