We help IT Professionals succeed at work.

open pdf or jpg inside access

titorober23
titorober23 asked
on
Medium Priority
800 Views
Last Modified: 2012-05-06
Hi
I need to link reports with a record, if the user needs to see detailed information they can open the report which could be a pdf, gif  or jpg; can i have a viewer inside acces, or do i have to create a link to the document and open outside access,
what is the best way to work this around
Comment
Watch Question

Techonology and Information Systems
Commented:
I use a function call I found a while ago.  Someone else deserves credit for the code... pasted below.
Then I call the function as:
fHandleFile Me.FileName, WIN_NORMAL
I use this to open PDF's and images using the user's associated application.
I think it is possible to embed a PDF or Image in an Access form - but it's always seem a better option to have a PDF open in Acrobat Reader, etc.

'***************Usage Examples***********************
'Open a folder:     ?fHandleFile("C:\TEMP\",WIN_NORMAL)
'Call Email app:    ?fHandleFile("mailto:dash10@hotmail.com",WIN_NORMAL)
'Open URL:          ?fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)
'Handle Unknown extensions (call Open With Dialog):
'                   ?fHandleFile("C:\TEMP\TestThis",Win_Normal)
'Start Access instance:
'                   ?fHandleFile("I:\mdbs\CodeNStuff.mdb", Win_NORMAL)
'****************************************************
 
Function fHandleFile(stFile As String, lShowHow As Long)
Dim lRet As Long, varTaskID As Variant
Dim stRet As String
    'First try ShellExecute
    lRet = apiShellExecute(hWndAccessApp, vbNullString, _
            stFile, vbNullString, vbNullString, lShowHow)
            
    If lRet > ERROR_SUCCESS Then
        stRet = vbNullString
        lRet = -1
    Else
        Select Case lRet
            Case ERROR_NO_ASSOC:
                'Try the OpenWith dialog
                varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
                        & stFile, WIN_NORMAL)
                lRet = (varTaskID <> 0)
            Case ERROR_OUT_OF_MEM:
                stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
            Case ERROR_FILE_NOT_FOUND:
                stRet = "Error: File not found.  Couldn't Execute!"
            Case ERROR_PATH_NOT_FOUND:
                stRet = "Error: Path not found. Couldn't Execute!"
            Case ERROR_BAD_FORMAT:
                stRet = "Error:  Bad File Format. Couldn't Execute!"
            Case Else:
        End Select
    End If
    fHandleFile = lRet & _
                IIf(stRet = "", vbNullString, ", " & stRet)
End Function

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Scott McDaniel (EE MVE )Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
ShellExecute doesn't really open the file "in" Access, it opens it in whatever program is associated with that file extension (if any).

One trick, if you want to actually display the item on an Access form, is to use a WebBrowser control and use the .Navigate property to allow that control to display your item.
Shawn CøadyTechonology and Information Systems

Commented:
I didn't mean to imply that the ShellExecute would open the file in Access.  I wasn't clear.  The function uses the application associated with the file type (based on extension)
 
Jeffrey CoachmanMIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012

Commented:
titorober23,

So to flesh this out for you...

In your main table you will have a Field(s) that contains the entire path and file name of the file you want to display:
For example you would have a field in your table named: ExternalRelatedFile
And a control on your main form named: txtExternalRelatedFile with a control source of: ExternalRelatedFile
And it would contain values similar to this:
c:\YourFolder\YourFile.001
Then you would create a form wth a Webbrowser control inserted.
(Design-->Controls-->ActiveX Controls)
Name the form something like frmExternalRelatedFile
On the OpenEvent of the form, put code like this:
 YourWebrowser.Navigate Forms!YourMainForm!txtExternalRelatedFile

Now put a button on your main form to open this new form.
The code on this button would be something like this:
  Docmd.openform "frmExternalRelatedFile"

(Points to Peter)
;-)

JeffCoachman

Author

Commented:
boag2000
Any working example of this
Scott McDaniel (EE MVE )Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Jeff gave you a pretty complete example of doing this. It's straightforward: Add a WebBrowser control to your form and set the .Navigate property of that control to whatever you want to display (in the example, that would be the file defined by txtExternalRelatedFile).
Jeffrey CoachmanMIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012

Commented:
Scott!

Sorry, I meant to say "Points to LSM"

I'll request that this be changed.

Jeff
Jeffrey CoachmanMIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012

Commented:
;-)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

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