Results 1 to 6 of 6
  1. #1
    Join Date
    May 2010
    Posts
    67

    Unanswered: Allow user to store the full path of a file on a form using a BROWSE button

    Hello All,

    I would like to give the user the ability to store and display the full path of a file on a form using a BROWSE button.

    Is this possible, if so how would I do this?

    Thanks in advance for your help!

  2. #2
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    This is one way to do it, there may be others. You need to add a reference to the Microsoft Office Object Library to get the Common Dialogs. Then the code below will work for a command button call cmdBrowse:

    Code:
    Private Sub cmdBrowse_Click()
    
        Dim dlgBrowse As FileDialog
        
        Set dlgBrowse = Application.FileDialog(msoFileDialogFolderPicker)
        
        With dlgBrowse
            
            .AllowMultiSelect = False
            If txtPath <> "" Then .InitialFileName = txtPath
            .Show
            
            If .SelectedItems.Count <> 0 Then
    
                txtPath = .SelectedItems(1) & IIf(Right(.SelectedItems(1), 1) = "\", "", "\")
                
            End If
            
        End With
        
        Set dlgBrowse = Nothing
    
    End Sub
    This code is not exactly what you are looking for (it is a folder picker not a file picker). But you should be able to modify it for your needs.

  3. #3
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Paul

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Oops; got distracted by a phone call. Sorry DC.
    Paul

  5. #5
    Join Date
    May 2010
    Posts
    67
    Thank you...

    I am getting a compile error "USER-DEFINED TYPE NOT DEFINED" on the FileDialog type

    I am referencing Microsoft Access 12.0 0bject Library.

    Any thought as to error?

  6. #6
    Join Date
    May 2010
    Posts
    67
    Hey DCKunkle and pbaldy,

    I was not referencing the Microsoft Office 12.0 Object Library. I working great now. Thank you for your help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •