Browse for Folder under AC2010

smig

Registered User.
Local time
Tomorrow, 00:08
Joined
Nov 25, 2009
Messages
2,209
I have a piece of code for brwosing for folder, that worked perfectly under AC2003.
After changing to AC2010 it will crash at the red line.
Code:
Option Compare Database

'http://www.mvps.org/access/api/api0002.htm
'Code courtesy of Terry Kreft

Private Type BROWSEINFO
    hOwner As Long
    pidlRoot As Long
    pszDisplayName As String
    lpszTitle As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Long
End Type

Private Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long


Public Function fn_BrowseDirectory(BrowseDirectoryTitle As String, BrowseDirectoryFlags) As String

On Error GoTo errHere

    Dim x As Long, bi As BROWSEINFO, dwIList As Long
    Dim szPath As String, wPos As Integer
    
    With bi
        .hOwner = hWndAccessApp
        .lpszTitle = BrowseDirectoryTitle
        .ulFlags = BrowseDirectoryFlags
    End With
    
   [B][COLOR="Red"] dwIList = SHBrowseForFolder(bi)[/COLOR][/B]
    szPath = Space$(512)
    x = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)
    
    If x Then
        wPos = InStr(szPath, Chr(0))
        fn_BrowseDirectory = Left$(szPath, wPos - 1)
    Else
        fn_BrowseDirectory = ""
    End If
   
   
ExitHere:
    Exit Function
 
errHere:
    Call ErrorHandling("", "fn_BrowseDirectory", Err, Err.Description)
    Resume ExitHere

End Function

Any idea ?

Thanks,
Tal
 
use FileDialog instead, just reference Microsoft Office XX.X on the VBE.
 
use FileDialog instead, just reference Microsoft Office XX.X on the VBE.

Can you give me a piece of code or reference me to the correct location, please.

Will it work if user only have AC2010 runTime, or do I need to deploy some DLL with my app ?
 
After some more search I found the answer in the Compatibility Between the 32-bit and 64-bit Versions of Office 2010 page.

changing some of the BROWSEINFO Types into LongPtr made it work :)
Code:
Private Type BROWSEINFO
    hOwner As [COLOR="Red"][B]LongPtr[/B][/COLOR]
    pidlRoot As Long
    pszDisplayName As String
    lpszTitle As String
    ulFlags As Long
    lpfn As [COLOR="Red"][B]LongPtr[/B][/COLOR]
    lParam As [COLOR="Red"][B]LongPtr[/B][/COLOR]
    iImage As Long
End Type

I prefer using the System's browser over the Office's one.
 

Users who are viewing this thread

Back
Top Bottom