Browse for a file from a Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CharT
    New Member
    • Sep 2011
    • 22

    Browse for a file from a Form

    Hello, using some VBA I was able to find online, I created a form that displays an image who's file path is stored in a table. The form works great, but I have to manually type the file path into a text box on the form. Is it possible to create a button (and macro??) that opens the normal windows browse for file feature and forwards the file path of the file selected to my text box so that it will automate the process? This seems like something that a lot of folks would like to know how to do. Thanks in advance!
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32656

    #2
    Check out Select a File or Folder using the FileDialog Object.

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      The following Code Segment will:
      1. Display the Microsoft Office File Dialog Box
      2. Set Filters to allow only specific Graphic File Formats
      3. Allow only a single File to be Selected
      4. Set the Default File Type for display to Bitmap (*.bmp)
      5. Show the Files in Detail View
      6. Write the Absolute PATH of the File selected to a Text Box named txtImagePath
        Code:
        'First, set a Reference to the Microsoft Office XX.X Object Library
        
        Dim strButtonCaption As String
        Dim strDialogTitle As String
        
        'Define your own Captions if necessary
        strButtonCaption = "Copy Path"
        strDialogTitle = "Select Graphic File"
        
        With Application.FileDialog(msoFileDialogFilePicker)
          With .Filters
            .Clear
              .Add "Windows Meta Files", "*.wmf"
              .Add "Enhanced Meta Files", "*.emf"
              .Add "Device Independent Bitmaps", "*.dib"
              .Add "Bitmaps", "*.bmp"
              .Add "Icons", "*.ico"
              .Add "Tag Image File Format", "*.tif"
              .Add "PC Paintbrush", "*.pcx"
          End With
          'The Show Method returns True if 1 or more files are selected
            .AllowMultiSelect = False       'Critical Line
            .FilterIndex = 4                'Bitmap files
            .ButtonName = strButtonCaption
            .InitialFileName = vbNullString
            .InitialView = msoFileDialogViewDetails     'Detailed View
            .Title = strDialogTitle
            .InitialFileName = CurrentProject.Path & "\"
          If .Show Then
            Me![txtImagePath] = .SelectedItems(1)
          End If
        End With

      Comment

      • CharT
        New Member
        • Sep 2011
        • 22

        #4
        Thanks so much, I will work on this!

        ** Edit from later post **
        Thank you SOOOOO much :) you both helped me immensely. I am glad there are smart people in this world!
        Last edited by NeoPa; Oct 1 '11, 11:38 AM. Reason: Merged in later post

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32656

          #5
          Very pleased to hear it. Good luck with your project :-)

          Comment

          Working...