Teedee Access VBA Teedee 2010
Browse for Folder
Home Tutorial Code Snippets

Browse for Folder - Using API

Use this dialog to return a Folder.
Code Snippet 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 Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long Private Const BIF_RETURNONLYFSDIRS = &H1 Public Function BrowseFolder(szDialogTitle As String) As String   Dim X As Long, bi As BROWSEINFO, dwIList As Long   Dim szPath As String, wPos As Integer       With bi         .hOwner = hWndAccessApp         .lpszTitle = szDialogTitle         .ulFlags = BIF_RETURNONLYFSDIRS     End With         dwIList = SHBrowseForFolder(bi)     szPath = Space$(512)     X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)         If X Then         wPos = InStr(szPath, Chr(0))         BrowseFolder = Left$(szPath, wPos - 1)     Else         BrowseFolder = ""     End If End Function

Requirements

comdlg32.dll is required & must be registered. More info here: http://support.microsoft.com/kb/1612 86/en-us