[AccessD] Get Folder Name via API

ACTEBS actebs at actebs.com.au
Tue Jan 6 10:07:28 CST 2004


Andy,

This should help you out (Not sure where I got it from originally -
apologies to the author):

Private Type BrowseInfo
    hWndOwner      As Long
    pIDLRoot       As Long
    pszDisplayName As Long
    lpszTitle      As Long
    ulFlags        As Long
    lpfnCallback   As Long
    lParam         As Long
    iImage         As Long
End Type

Private Const BIF_RETURNONLYFSDIRS = 1
Private Const MAX_PATH = 260

Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _
       (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" _
       (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" _
       (ByVal pidList As Long, ByVal lpBuffer As String) As Long

Public Function BrowseForFolder(hWndOwner As Long, sPrompt As String) As
String

    Dim iNull As Integer
    Dim lpIDList As Long
    Dim lResult As Long
    Dim sPath As String
    Dim udtBI As BrowseInfo

    With udtBI
        .hWndOwner = hWndOwner
        .lpszTitle = lstrcat(sPrompt, "")
        .ulFlags = BIF_RETURNONLYFSDIRS
    End With

    lpIDList = SHBrowseForFolder(udtBI)
    If lpIDList Then
        sPath = String$(MAX_PATH, 0)
        lResult = SHGetPathFromIDList(lpIDList, sPath)
        Call CoTaskMemFree(lpIDList)
        iNull = InStr(sPath, vbNullChar)
        If iNull Then
            sPath = Left$(sPath, iNull - 1)
        End If
    End If

    BrowseForFolder = sPath

End Function

You can use it as in the following example:

Me!YourTextBox = BrowseForFolder(0, "Heading For The Browse Dialogue
Box")

HTH
Regards
Vlad

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Andy Lacey
Sent: Wednesday, 7 January 2004 2:42 AM
To: Access Developers discussion and problem solving
Subject: [AccessD] Get Folder Name via API


Must've done thsi before but can't find it. I want to ask the user for a
folder name (into which I'm going to store stuff). I want to use the
Windows common file dialog so that it looks neat and offers to create a
new folder and so on. However I don't want to put a Common Dialog
control on the form (always has version issues) so want to use the API
method. But the code I have (from Dev Ashish) insists on a filename not
just a folder, and the other code on his site to browse a folder list
doesn't use the normal dialog. Anyone got code for this?

--
Andy Lacey
http://www.minstersystems.co.uk


________________________________________________
Message sent using UebiMiau 2.7.2

_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com





More information about the AccessD mailing list