Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browse for File - return path and filename

Status
Not open for further replies.

firsttube

Technical User
Apr 21, 2004
165
0
0
CA
I need a file browser window to open, and the user to pick a file from the browser, and have the file path and file name returned as a string. I have this code:
Code:
Function PickFolder(strStartDir As Variant) As String
    Dim SA As Object, F As Object
    Set SA = CreateObject("Shell.Application")
    Set F = SA.BrowseForFolder(0, "Choose a folder", 0, strStartDir)
    If (Not F Is Nothing) Then
        PickFolder = F.Items.Item.Path
    End If
    Set F = Nothing
    Set SA = Nothing
End Function

but for some reason it only allows me to select folders, not drill down to the files inside the folder. Can this be done?

Information is not Knowledge, Knowledge is not Wisdom, Wisdom is not Truth, Truth is not Beauty, Beauty is not Love, Love is not Music, Music is the best.
 



Hi,

Check out the GetOpenFilename Method.

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
I got this working:
Code:
Dim fDialog As Office.FileDialog
        Dim varFile As Variant
        
        ' Set up the File Dialog.
        Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
        
        With fDialog
            ' Allow user to make multiple selections in dialog box
            .AllowMultiSelect = False
            
            'Set the title of the dialog box.
            .Title = "Please select a file"
            
            'Clear out the current filters, and add our own.
            .Filters.Clear
            .Filters.Add "Text Files", "*.csv"
                    
            ' Show the dialog box. If the .Show method returns True, the
            ' user picked at least one file. If the .Show method returns
            ' False, the user clicked Cancel.
            If .Show = True Then
                ' Loop through each file selected and add it to our list box.
                For Each varFile In .SelectedItems
                    strPathFile = varFile
                Next
                DoCmd.TransferText acImportDelim, , strTable, strPathFile, ynFieldName
            Else
                MsgBox "You clicked Cancel in the file dialog box."
            End If
        End With

Information is not Knowledge, Knowledge is not Wisdom, Wisdom is not Truth, Truth is not Beauty, Beauty is not Love, Love is not Music, Music is the best.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top