Results 1 to 4 of 4
  1. #1
    Iain is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Location
    Aberdeenshire, Scotland
    Posts
    42

    ShellExecute file association in Window 7 64-bit does not open the default program for jpg files

    Applogies if I have posted this in the wrong area but I was unsure where exactly it should go.



    I have a database which uses the ShellExecute to open jpg files with the Windows default picture viewer.

    The database was originally on a 32-bit XP machine running Access 2007.

    Now, although the variables all contain the correct data the code simply does nothing, not even gives an error message.

    Code:
    Private Sub ViewFile_Click()
    On Error GoTo MyError
    Dim Task As Long
    Dim Action As String
    Dim OKToView As Boolean
    Dim FilePathToView As String
    
    
    'Initialise variables
    OKToView = False
    FilePathToView = txtFilePath
    
    If Not IsNull(txtFilePath) Then
        OKToView = True
        If OKToView = True Then
            FilePathToView = txtFilePath
            If FilePathToView <> "" Then
                Action = "Open"
                Task = ShellExecute(0, Action, FilePathToView, "", "", 0)
            Else
                Beep
                MsgBox "No File Path exists"
            End If
        End If
    End If
    
    MyErrorExit:
        Exit Sub
    
    
    MyError:
        Dim Msg As String
        Msg = "Error in Sub ViewFile_Click" & Err.Number & ": " & Err.Description
        MsgBox Msg
        Resume MyErrorExit
    End Sub
    Is it possible to re-write the code so that it operates in a Windows 7 -64-bit environment?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,820
    Trying to test the code. But errors on undeclared variable txtFilePath. Where is this variable declared and how is it set? Also, VBA doesn't recognize ShellExecute function. I had to find this on web.

    I got this to work:
    Code:
    Public Declare 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 Sub ViewFile()
    Dim Task As Long
    Task = ShellExecute(0, "Open", "C:\Users\June\Image.jpg", "", "", 0)
    End Sub
    Here is an alternative to calling the Shell: http://allenbrowne.com/func-GoHyperlink.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Iain is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Location
    Aberdeenshire, Scotland
    Posts
    42
    Quote Originally Posted by June7 View Post
    Trying to test the code. But errors on undeclared variable txtFilePath. Where is this variable declared and how is it set? Also, VBA doesn't recognize ShellExecute function. I had to find this on web.
    txtFilePath is the name of a textbox on the same form as the view button. This is populated by a query which loads the data from a table.

    The ShellExicute function has worked satisfactorily on the XP/32-bit platform for several years now and the problem only manifest itself on the 64-bit platform.

    Iwill try out your code tomorrow when I have access to the other machine and get back to you then.

    Thanks for your help.

    iain

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,820
    You also have the option to dynamically display images on form or report by using Image Control and setting its ControlSource property with the file path to the external image file.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 10-23-2013, 08:11 AM
  2. Resuming program execution after a modal window
    By dccjr in forum Programming
    Replies: 2
    Last Post: 08-13-2013, 06:14 PM
  3. Access as Default Program for Device
    By Meep in forum Forms
    Replies: 1
    Last Post: 04-13-2012, 10:40 AM
  4. Open (shell) a program and pass a file
    By Olszanski in forum Programming
    Replies: 2
    Last Post: 07-27-2010, 03:52 PM
  5. Default window
    By Tareq_1993 in forum Access
    Replies: 2
    Last Post: 11-26-2009, 09:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums