[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

open pdf or jpg inside access

Posted on 2009-02-10
9
Medium Priority
?
780 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
0
Comment
Question by:titorober23
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 3

Accepted Solution

by:
Shawn Cøady earned 800 total points
ID: 23602416
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

0
 
LVL 85

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 400 total points
ID: 23605097
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.
0
 
LVL 3

Expert Comment

by:Shawn Cøady
ID: 23606636
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)
 
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 23619732
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
0
 

Author Comment

by:titorober23
ID: 23621756
boag2000
Any working example of this
0
 
LVL 85
ID: 23622104
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).
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 23624435
Scott!

Sorry, I meant to say "Points to LSM"

I'll request that this be changed.

Jeff
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 23635219
;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

834 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