open pdf or jpg inside access

Posted on 2009-02-10
Last Modified: 2012-05-06
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
Question by:titorober23
    LVL 3

    Accepted Solution

    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("",WIN_NORMAL)
    'Open URL:          ?fHandleFile("", 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
            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

    LVL 84

    Assisted Solution

    by:Scott McDaniel (Microsoft Access MVP - EE MVE )
    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.
    LVL 3

    Expert Comment

    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)
    LVL 74

    Expert Comment

    by:Jeffrey Coachman

    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:
    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)


    Author Comment

    Any working example of this
    LVL 84
    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).
    LVL 74

    Expert Comment

    by:Jeffrey Coachman

    Sorry, I meant to say "Points to LSM"

    I'll request that this be changed.

    LVL 74

    Expert Comment

    by:Jeffrey Coachman

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    The first two articles in this short series — Using a Criteria Form to Filter Records ( and Building a Custom Filter ( — discuss in some detail how a form can be…
    Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
    In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now