Share via

Image File

Anonymous
2022-06-08T19:52:34+00:00

Hi

I would like to have any function or routine to open an image file located outside the access database without inserting the image to access form or report.

Best Regards

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2022-06-09T06:49:11+00:00

    Use an API call.

    This is the complete code you can save as a module named, say, ShowDocumentFile:

    Option Compare Database Option Explicit

    ' API declarations for OpenDocumentFile.
    ' Documentation:
    '   https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea
    '
    Private Declare PtrSafe 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
    
    Private Declare PtrSafe Function GetDesktopWindow Lib "USER32" () _
        As Long
        
    ' Enum for ShowWindow constants (selection).
    ' Documentation:
    '   https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow
    '
    Public Enum SwShowCommand
        swShowNormal = 1
        swShowMinimized = 2
        swShowMaximized = 3
    End Enum
       
    ' Open a document file using its default viewer application.
    ' Optionally, the document can be opened minimised or maximised.
    '
    ' Returns True if success, False if not.
    ' Will not raise an error if the path or file is not found.
    '
    ' 2022-03-12. Gustav Brock, Cactus Data ApS, CPH.
    '
    Public Function OpenDocumentFile( _
        ByVal File As String, _
        Optional ByVal ShowCommand As SwShowCommand = swShowNormal) _
        As Boolean
    
        Const OperationOpen     As String = "open"
        Const MinimumSuccess    As Long = 32
        ' Shall not have a value for opening a document.
        Const Parameters        As String = ""
        
        Dim Handle      As Long
        Dim Directory   As String
        Dim Instance    As Long
        Dim Success     As Boolean
        
        Handle = GetDesktopWindow
        Directory = Environ("Temp")
    
        Instance = ShellExecute(Handle, OperationOpen, File, Parameters, Directory, ShowCommand)
        ' If the function succeeds, it returns a value greater than MinimumSuccess.
        Success = (Instance > MinimumSuccess)
        
        OpenDocumentFile = Success
    
    End Function
    

    Was this answer helpful?

    0 comments No comments
  2. DBG 11,711 Reputation points Volunteer Moderator
    2022-06-08T20:09:56+00:00

    Hi. Check out the Application.FollowHyperlink method. Also, look into the ShellExecute API.

    Was this answer helpful?

    0 comments No comments