Microsoft Access: Select A Folder

Platform:Microsoft Access
Task:Select A Folder
Discussion:
VBA select folder relies upon the Microsoft Shell Controls And Automation object library. You will need to set a Reference to it. In the VBA Editor's Tools menu, click References... scroll down to "Microsoft Shell Controls And Automation" and choose it. We have to add it to be able to use the Shell32 library. From http://www.your-save-time-and-improve-quality-technologies-online-resource.com/vba-select-folder.html
Example:
Sub FolderSelection()
    Dim MyPath As String
    MyPath = SelectFolder("Select Folder", "")
    If Len(MyPath) Then
        MsgBox MyPath
    Else
        MsgBox "Cancel was pressed"
    End If
End Sub

'Both arguements are optional. The first is the dialog caption and
'the second is is to specify the top-most visible folder in the
'hierarchy. The default is "My Computer."

Function SelectFolder(Optional Title As String, Optional TopFolder _
                         As String) As String
    Dim objShell As New Shell32.Shell
    Dim objFolder As Shell32.Folder

'If you use 16384 instead of 1 on the next line,
'files are also displayed
    Set objFolder = objShell.BrowseForFolder _
                            (0, Title, 1, TopFolder)
    If Not objFolder Is Nothing Then
        SelectFolder = objFolder.Items.Item.Path
    End If
End Function
Back to Index