Link to home
Start Free TrialLog in
Avatar of Phil
PhilFlag for United States of America

asked on

Displaying a PDF file via VBA within Microsoft Access 2010 in 2003 mode without irritating Microsoft confirmation

I'm trying to display a PDF file with VBA but I get this irritating dialog wanting confirmation. I'm using Access 2010 in 2003 mode. I wanted to allow users to do this without creating a form with an embedded browser control

Since I can't get rid of the confirmation, I'm trying to use a form to contain the PDF file. I found an ActiveX browser control that I should be able to use in a form but the version of browser control doesn't seem to work as I can't find how to define the file link.

Thanks so much!!
Avatar of Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP)
Flag of Denmark image

I *think* you could use a webbrowser control to display it, however I also think that the webbrowser control was only added in 2010. Its been quite a while since I used 2003, and I don't have a copy installed anymore.

An alternative is to get rid of the warning message, which you should be able to do with the link here;
http://access.mvps.org/access/api/api0018.htm
dialog wanting confirmation.
...and the message says...?

This fairly common code works fine for me in all versions of Access that I have tried it in...
(Obviously you will have to use your specific file location for your adobe PDF program executable)
Private Sub Command0_Click()
Dim varCmd As Variant
varCmd = Shell("C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" & " " & "C:\YourFolder\YourPDF.PDF", vbNormalFocus)
End Sub

Open in new window

FWIW, ...this is fairly standard code to display a PDF in a form, using a web browser control...

Me.WebBrowser1.Navigate "C:\YourFolder\Yourpdf.pdf"
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
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 Phil

ASKER

When I execute the following, the pdf displays properly after the irritating confirmation.

FollowHyperlink path2 & ".pdf", , True

I tried your code:
varCmd = Shell("C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" & " " & path2 & ".PDF", vbNormalFocus)

and I get an error saying the file cannot be foundUser generated image
You did not post the code you used, ...but since the code opened Adobe, ...then the fist part of the snippet is working...
You will only get that error when you don't properly specify the actual full path to your PDF file...

...Perhaps "Path2" already contains the extension?..., or it has an incorrect drive, ...etc)
Always *Keep things Simple* to test...
Forget variables for now, ...to test:
Drop a simple PDF on your root directory, then...please type out the full path, filename and extension...
(as I did in my example...)
For example...:
'varCmd = Shell("C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" & " " & "C:\Test.PDF", vbNormalFocus)

Only when this is working can you add a more complex path...
Then add any variables...

Jeff
Since you never mentioned the actual error message, ...I will presume that it is the:
    "Security Concern, ....Location my be unsafe"
...message.

Follow Hyperlink was only ever created for hyperlinks specifically, ...not really for file locations.
Depending on your environment, it might work for files, ...or it might not.

There is code to disable the messsage:
https://support.microsoft.com/en-us/kb/925757
...but this may open you up to security issues.

JeffCoachman
Avatar of Phil

ASKER

Your solution worked perfectly. Thank you very much!
Great...

Glad I could help
;-)
Jeff