none
API function GetOpenFileName doesn't work in Office 64 version

    Question

  • In a standard module in MS Access (32 bit), I used the API function GetOpenFileName. It always worked well, but in (converted to) the 64 bit version of Office 2010, the file box fails to open. Does anyone know why? Here is the code converted to 64 bit and the 'TestGetFile' which calls GetOpenFileName. The function TestGetFile shows the filename as a result (in the 32 bit version). Or is there another way?

    Public Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" Alias _
            "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
        
    Public Type OPENFILENAME
        lStructSize As Long
        hwndOwner As LongPtr
        hInstance As LongPtr
        lpstrFilter As String
        lpstrCustomFilter As String
        nMaxCustFilter As Long
        nFilterIndex As Long
        lpstrFile As String
        nMaxFile As Long
        lpstrFileTitle As String
        nMaxFileTitle As Long
        lpstrInitialDir As String
        lpstrTitle As String
        flags As Long
        nFileOffset As Integer
        nFileExtension As Integer
        lpstrDefExt As String
        lCustData As Long
        lpfnHook As LongPtr
        lpTemplateName As String
    End Type

    The calling function TestGetFile

    Public Function TestGetFile(strTitle As String) As String
        
        Dim OpenFile    As OPENFILENAME
        Dim lReturn     As Long
        Dim sFilter     As String
        
        OpenFile.lStructSize = LenB(OpenFile)
        OpenFile.hwndOwner = 0
        OpenFile.lpstrFile = String(257, 0)
        OpenFile.nMaxFile = LenB(OpenFile.lpstrFile) - 1
        OpenFile.lpstrFileTitle = OpenFile.lpstrFile
        OpenFile.nMaxFileTitle = OpenFile.nMaxFile
        OpenFile.lpstrInitialDir = "C:\"
        OpenFile.lpstrTitle = strTitle
        OpenFile.flags = 0
        lReturn = GetOpenFileName(OpenFile)
        
        If lReturn = 0 Then
            TestGetFile = ""
        Else
            TestGetFile = Trim(Left(OpenFile.lpstrFile, InStr(1, OpenFile.lpstrFile, vbNullChar) - 1))
        End If
        
    End Function

    Monday, July 02, 2012 1:35 PM

Answers

All replies