browse for file and then copy file path into text box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • n8kindt
    New Member
    • Mar 2008
    • 221

    browse for file and then copy file path into text box

    i have an email program set up that is discussed in Bytes:array for email recipients thread. here's a picture to get the visual of what i'm trying to do

    [IMGnothumb]http://i3.photobucket. com/albums/y72/n8kindt/emailsend.jpg[/IMGnothumb]

    currently, the button at the bottom "Browse..." is an empty button. i want it to open an action that allows the user to select a file and then copy the file path to the attachment text box. just like you would in any email program. anybody know how i could go about doing this?
    Last edited by zmbd; Jan 25 '14, 05:16 AM. Reason: [z{since this may come alive, displayed image inline and cleared URL}]
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Code:
    'CRITICAL STEP!
    'First, set a Reference to the Microsoft Office XX.X Object Library
    
    Dim strButtonCaption As String
    Dim strDialogTitle As String
    Dim strAttachment As String
    Dim varItem As Variant
    
    strButtonCaption = "<Your Button Name Here>"
    strDialogTitle = "<Your File Dialog Title Here>"
    
    With Application.FileDialog(msoFileDialogFilePicker)
      With .Filters
        .Clear
        .Add "All Files", "*.*"     'Allow ALL File types
      End With
      
      'The Show Method returns True if 1 or more files are selected
        .AllowMultiSelect = False       'Critical Line/Single File selection
        '.FilterIndex = 1               'not really relevant
        .ButtonName = strButtonCaption
        .InitialFileName = vbNullString
        .InitialView = msoFileDialogViewDetails     'Detailed View
        .Title = strDialogTitle
        
      If .Show Then
        For Each varItem In .SelectedItems      'There will only be 1 since
                                                'AllowMultiSelect = False
          'Assuming your Text Box Name is txtAttachment
          strAttachment = varItem
            Me![txtAttachment] = strAttachment
        Next varItem
      End If
    End With

    Comment

    • n8kindt
      New Member
      • Mar 2008
      • 221

      #3
      Originally posted by ADezii
      Code:
      'CRITICAL STEP!
      'First, set a Reference to the Microsoft Office XX.X Object Library
      
      Dim strButtonCaption As String
      Dim strDialogTitle As String
      Dim strAttachment As String
      Dim varItem As Variant
      
      strButtonCaption = "<Your Button Name Here>"
      strDialogTitle = "<Your File Dialog Title Here>"
      
      With Application.FileDialog(msoFileDialogFilePicker)
        With .Filters
          .Clear
          .Add "All Files", "*.*"     'Allow ALL File types
        End With
        
        'The Show Method returns True if 1 or more files are selected
          .AllowMultiSelect = False       'Critical Line/Single File selection
          '.FilterIndex = 1               'not really relevant
          .ButtonName = strButtonCaption
          .InitialFileName = vbNullString
          .InitialView = msoFileDialogViewDetails     'Detailed View
          .Title = strDialogTitle
          
        If .Show Then
          For Each varItem In .SelectedItems      'There will only be 1 since
                                                  'AllowMultiSelect = False
            'Assuming your Text Box Name is txtAttachment
            strAttachment = varItem
              Me![txtAttachment] = strAttachment
          Next varItem
        End If
      End With
      WOW, unbelievable! that worked perfectly! where did u get that code? i googled all over the place and was unable to find ANYTHING. thanks a lot!

      cheers,
      nate

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by n8kindt
        WOW, unbelievable! that worked perfectly! where did u get that code? i googled all over the place and was unable to find ANYTHING. thanks a lot!

        cheers,
        nate
        That is the standard Office File Dialog code with slight modifications.

        Comment

        • Mas Juliza Alias
          New Member
          • Aug 2010
          • 67

          #5
          i have a quite similar problem. where should i paste the codes? is it under the cmdBrowse_Click ()?? i've tried it but there is a run time error occured. (sorry, i am a beginner in programming)

          Comment

          • EADJLT
            New Member
            • Jan 2014
            • 1

            #6
            WOW Code doesn't work in Acces 2013

            This code does not work in access 2013. I have been looking a couple a days for the right code and thought I found it.

            I want to browse and select a file en then save the path of te file to a textbox. The saved data in the textfield must be saved in a field in a table.

            Can you help me?

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              This code does not work in access 2013
              1. What exactly do you mean when you say it doesn't work, are you getting any Error Messages?
              2. Did you set a Reference to the Microsoft Office XX.X Object Library?

              Comment

              Working...