Answered by:
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 2, 2012 1:35 PM
Answers
-
Hi Ed,
I've solved the problem: I did not set OpenFile.lpstrFilter = ""
- Proposed as answer by Ed Price - MSFTMicrosoft employee Tuesday, July 10, 2012 1:54 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Tuesday, July 10, 2012 1:54 AM
Friday, July 6, 2012 12:58 PM
All replies
-
- Proposed as answer by Ed Price - MSFTMicrosoft employee Wednesday, July 4, 2012 9:08 PM
- Unproposed as answer by Ed Price - MSFTMicrosoft employee Tuesday, July 10, 2012 1:54 AM
Tuesday, July 3, 2012 11:32 PM -
Hi Ed,
I've solved the problem: I did not set OpenFile.lpstrFilter = ""
- Proposed as answer by Ed Price - MSFTMicrosoft employee Tuesday, July 10, 2012 1:54 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Tuesday, July 10, 2012 1:54 AM
Friday, July 6, 2012 12:58 PM -
Excellent ! this works !Monday, September 7, 2015 8:00 PM