?
Solved

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

Posted on 2011-04-22
12
Medium Priority
?
266 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

0
Comment
Question by:Bevos
  • 6
  • 5
11 Comments
 
LVL 85
ID: 35449224
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

0
 

Author Comment

by:Bevos
ID: 35449476
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.
0
 
LVL 85
ID: 35449492
Is Me.Filename the FULL path to the PDF file, including the directory?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Bevos
ID: 35449510
Yes, its stored as such:
C:\Documents and Settings\Bevos\My Documents\Wrede2009.pdf
0
 

Author Comment

by:Bevos
ID: 35449535
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?
0
 
LVL 85
ID: 35449556
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.

0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 total points
ID: 35449578
If that doesn't work, you can always try ShellExecute. To use that, place the following line in the General Declarations section of a standard Code Module:

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Now call your file like this:

Dim sFile As String
sFile = Chr(34) & Me.FileName & Chr(34)
ShellExecute 0, "Open", sFile, "", "", 1
0
 

Author Comment

by:Bevos
ID: 35449694
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.
0
 
LVL 85
ID: 35449754
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).
0
 

Author Comment

by:Bevos
ID: 35450048
Thanks so much again! I'll look into these resources :)
0
 
LVL 85
ID: 35450152
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have had my own IT business for a very long time. I started mostly with hardware and after about a year started to notice a common theme. I had shelves with software boxes -- Peachtree, Quicken, Sage, Ouickbooks -- and yet most of my clients were…
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question