Need "Browse for File" button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • truthlover
    New Member
    • Dec 2007
    • 107

    Need "Browse for File" button

    I need some help. I need a button on an Access form that allows the user to browse for a file on our network, and insert it in a field (rather than having to type a path). I dont need any filters because the files can be any number of formats.

    I've come across a couple of so-called "simple" solutions, but for the life of me, I either cant understand them or I cant get them to work. I know nothing about VB so if someone can provide a truly simple answer (preferably something I could cut and paste) with clear instructions on how to actually get it to work, I'd be VERY grateful.

    Oh, I am coding this in Access 2000, but if I need to, I can code it in Access 2002-2003.

    Thanks!
    Barb
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by truthlover
    I need some help. I need a button on an Access form that allows the user to browse for a file on our network, and insert it in a field (rather than having to type a path). I dont need any filters because the files can be any number of formats.

    I've come across a couple of so-called "simple" solutions, but for the life of me, I either cant understand them or I cant get them to work. I know nothing about VB so if someone can provide a truly simple answer (preferably something I could cut and paste) with clear instructions on how to actually get it to work, I'd be VERY grateful.

    Oh, I am coding this in Access 2000, but if I need to, I can code it in Access 2002-2003.

    Thanks!
    Barb
    1. Set a Reference to Microsoft Office XX.X Object Library.
    2. Copy and Paste the following code wherever appropriate, changing the name of the Text Box
      [CODE=vb]
      Dim fdg As FileDialog, vrtSelectedItem As Variant
      Dim strSelectedFile As String

      Set fdg = Application.Fil eDialog(msoFile DialogFilePicke r)

      With fdg
      .AllowMultiSele ct = False
      .InitialView = msoFileDialogVi ewDetails
      If .Show = -1 Then
      For Each vrtSelectedItem In .SelectedItems 'onby be 1
      strSelectedFile = vrtSelectedItem
      Next vrtSelectedItem
      Me![txtSelectedFile] = strSelectedFile
      Else 'The user pressed Cancel.
      End If
      End With

      Set fd = Nothing[/CODE]
    3. Let me know if you have any problems.

    Comment

    • truthlover
      New Member
      • Dec 2007
      • 107

      #3
      Set a Reference to Microsoft Office XX.X Object Library.
      How do I do that?

      Copy and Paste the following code wherever appropriate,
      I'm afraid I couldnt begin to know where it's appropriate. Can you be more specific?

      changing the name of the Text Box
      Do you mean I have to change the name of the actual Text Box (what do I change it to?) or do you mean I have to rename the Text Box reference in the below code?

      Sorry, I warned you I knew nothing about this

      Thanks!
      Barb

      Originally posted by ADezii
      1. Set a Reference to Microsoft Office XX.X Object Library.
      2. Copy and Paste the following code wherever appropriate, changing the name of the Text Box
        [CODE=vb]
        Dim fdg As FileDialog, vrtSelectedItem As Variant
        Dim strSelectedFile As String

        Set fdg = Application.Fil eDialog(msoFile DialogFilePicke r)

        With fdg
        .AllowMultiSele ct = False
        .InitialView = msoFileDialogVi ewDetails
        If .Show = -1 Then
        For Each vrtSelectedItem In .SelectedItems 'onby be 1
        strSelectedFile = vrtSelectedItem
        Next vrtSelectedItem
        Me![txtSelectedFile] = strSelectedFile
        Else 'The user pressed Cancel.
        End If
        End With

        Set fd = Nothing[/CODE]
      3. Let me know if you have any problems.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by truthlover
        How do I do that?



        I'm afraid I couldnt begin to know where it's appropriate. Can you be more specific?



        Do you mean I have to change the name of the actual Text Box (what do I change it to?) or do you mean I have to rename the Text Box reference in the below code?

        Sorry, I warned you I knew nothing about this

        Thanks!
        Barb
        1. To set a Reference to the Microsoft Office Object Library
          • In Form Design View
          • Select View from the Menu Bar ==> Code
          • Select Tools from the Menu Bar ==> References
          • Scroll down to the Microsoft Office XX.X Object Library
          • Select the Check Box next to this Option
          • Click on OK
        2. Select the Text Box on your Form (Design View) that will show the Path to the selected File
          • Right Click on Text Box ==> Properties ==> All Tab ==> Name.
          • Rename the Text Box to txtSelectedFile
          • Close Properties Dialog Box

        Comment

        • truthlover
          New Member
          • Dec 2007
          • 107

          #5
          Ok, I got that. Now where does the code go? And is there anything I have to do to connect the code to the text box?



          Originally posted by ADezii
          1. To set a Reference to the Microsoft Office Object Library
            • In Form Design View
            • Select View from the Menu Bar ==> Code
            • Select Tools from the Menu Bar ==> References
            • Scroll down to the Microsoft Office XX.X Object Library
            • Select the Check Box next to this Option
            • Click on OK
          2. Select the Text Box on your Form (Design View) that will show the Path to the selected File
            • Right Click on Text Box ==> Properties ==> All Tab ==> Name.
            • Rename the Text Box to txtSelectedFile
            • Close Properties Dialog Box

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Originally posted by truthlover
            Ok, I got that. Now where does the code go? And is there anything I have to do to connect the code to the text box?
            Now where does the code go?
            The most obvious location would be the Click() Event of a Command Button.
            And is there anything I have to do to connect the code to the text box?
            Line #13 connects the code (selected File) to the Text Box as long as it is named txtSelectedFile.

            Comment

            • truthlover
              New Member
              • Dec 2007
              • 107

              #7
              Thanks, that worked great!

              One question, though, is that even though I have it set up as a hyperlink, when it's clicked on, nothing happens. Is there some extra coding it needs?

              Also, is there any way of also getting an image of the file selected to display?

              Thanks so much!
              Barb


              Originally posted by ADezii
              The most obvious location would be the Click() Event of a Command Button.

              Line #13 connects the code (selected File) to the Text Box as long as it is named txtSelectedFile.

              Comment

              • ADezii
                Recognized Expert Expert
                • Apr 2006
                • 8834

                #8
                Originally posted by truthlover
                Thanks, that worked great!

                One question, though, is that even though I have it set up as a hyperlink, when it's clicked on, nothing happens. Is there some extra coding it needs?

                Also, is there any way of also getting an image of the file selected to display?

                Thanks so much!
                Barb
                You definately should have mentioned these 'little details' up front! Is the Control Source for txtSelectedFile a Hyperlink Data Type?

                Comment

                • truthlover
                  New Member
                  • Dec 2007
                  • 107

                  #9
                  Originally posted by ADezii
                  You definately should have mentioned these 'little details' up front! Is the Control Source for txtSelectedFile a Hyperlink Data Type?
                  Sorry. I didint mention it because it was working with the "edit hyperlink" code I tried first.

                  Anyway, yes, I currently have the control source as a Hyperlink. I also had some trouble initially getting the hyperlink to not use http:// to target the link. I may have done it wrong (i set the format to "file://") so if that's wrong, please tell me the correct method.

                  Thanks for all your patience!!

                  Comment

                  • ADezii
                    Recognized Expert Expert
                    • Apr 2006
                    • 8834

                    #10
                    Originally posted by truthlover
                    Sorry. I didint mention it because it was working with the "edit hyperlink" code I tried first.

                    Anyway, yes, I currently have the control source as a Hyperlink. I also had some trouble initially getting the hyperlink to not use http:// to target the link. I may have done it wrong (i set the format to "file://") so if that's wrong, please tell me the correct method.

                    Thanks for all your patience!!
                    You are quite welcome. Now, let's work on the Hyperlink part first. Make a slight change to the code in Line #11, as listed below. Select a Local File first, see if you can Navigate to it via the Hyperlink on the Form Field (txtSelectedFil e), then a File on the Network. Let me know how you make out:
                    [CODE=vb]
                    Dim fdg As FileDialog, vrtSelectedItem As Variant
                    Dim strSelectedFile As String

                    Set fdg = Application.Fil eDialog(msoFile DialogFilePicke r)

                    With fdg
                    .AllowMultiSele ct = False
                    .InitialView = msoFileDialogVi ewDetails
                    If .Show = -1 Then
                    For Each vrtSelectedItem In .SelectedItems 'onby be 1
                    strSelectedFile = vrtSelectedItem & "#" & vrtSelectedItem
                    Next vrtSelectedItem
                    Me![txtSelectedFile] = strSelectedFile
                    Else 'The user pressed Cancel.
                    End If
                    End With

                    Set fd = Nothing[/CODE]

                    Comment

                    • truthlover
                      New Member
                      • Dec 2007
                      • 107

                      #11
                      That worked perfectly, thanks!!

                      What about getting an image to display? Is it possible to have that function also display as an image? PDF would be the preferred format, since that's the output of our scanners, but if that's not possible, a .tiff or a .jpg would work.

                      Access does have a method of doing it, but to be honest, it's clunky and difficult and the people using it are not going to get it so if i can get this one function to work, it would be fabulous.

                      Even if I need a separate button to get the image to display, it would be better than not having the ability to display the image.

                      Thanks again
                      -Barb


                      Originally posted by ADezii
                      You are quite welcome. Now, let's work on the Hyperlink part first. Make a slight change to the code in Line #11, as listed below. Select a Local File first, see if you can Navigate to it via the Hyperlink on the Form Field (txtSelectedFil e), then a File on the Network. Let me know how you make out:
                      [CODE=vb]
                      Dim fdg As FileDialog, vrtSelectedItem As Variant
                      Dim strSelectedFile As String

                      Set fdg = Application.Fil eDialog(msoFile DialogFilePicke r)

                      With fdg
                      .AllowMultiSele ct = False
                      .InitialView = msoFileDialogVi ewDetails
                      If .Show = -1 Then
                      For Each vrtSelectedItem In .SelectedItems 'onby be 1
                      strSelectedFile = vrtSelectedItem & "#" & vrtSelectedItem
                      Next vrtSelectedItem
                      Me![txtSelectedFile] = strSelectedFile
                      Else 'The user pressed Cancel.
                      End If
                      End With

                      Set fd = Nothing[/CODE]

                      Comment

                      • ADezii
                        Recognized Expert Expert
                        • Apr 2006
                        • 8834

                        #12
                        Originally posted by truthlover
                        That worked perfectly, thanks!!

                        What about getting an image to display? Is it possible to have that function also display as an image? PDF would be the preferred format, since that's the output of our scanners, but if that's not possible, a .tiff or a .jpg would work.

                        Access does have a method of doing it, but to be honest, it's clunky and difficult and the people using it are not going to get it so if i can get this one function to work, it would be fabulous.

                        Even if I need a separate button to get the image to display, it would be better than not having the ability to display the image.

                        Thanks again
                        -Barb
                        I could incorporate code which would check the Selected File's Extension, and if it is one of the standard Graphic File Formats (*.bmp, *.gif, *.wmf, *.jpg) dynamically load the Image into an Iamge Control. This Control would have to have practical dimensions to be effective. Is this what you are looking for?

                        Comment

                        • truthlover
                          New Member
                          • Dec 2007
                          • 107

                          #13
                          Yes, that's exactly what I need.

                          Thanks so much for your help and your patience.

                          Have a wonderful weekend
                          -Barb

                          Originally posted by ADezii
                          I could incorporate code which would check the Selected File's Extension, and if it is one of the standard Graphic File Formats (*.bmp, *.gif, *.wmf, *.jpg) dynamically load the Image into an Iamge Control. This Control would have to have practical dimensions to be effective. Is this what you are looking for?

                          Comment

                          • ADezii
                            Recognized Expert Expert
                            • Apr 2006
                            • 8834

                            #14
                            Originally posted by truthlover
                            Yes, that's exactly what I need.

                            Thanks so much for your help and your patience.

                            Have a wonderful weekend
                            -Barb
                            You have a nice weekend, also. I'll try to have a look at it during this weekend and see what I can come up with.

                            Comment

                            • ADezii
                              Recognized Expert Expert
                              • Apr 2006
                              • 8834

                              #15
                              Originally posted by truthlover
                              Yes, that's exactly what I need.

                              Thanks so much for your help and your patience.

                              Have a wonderful weekend
                              -Barb
                              I'm posting some revised code based on an Image Control on your Form named imgSelectedFile , but please download the Attached Test Database on this Thread to get a much clearer picture of what's going on. Let me know how you make out.
                              [CODE=vb]
                              Dim fdg As FileDialog, vrtSelectedItem As Variant
                              Dim strSelectedFile As String, strImagePath As String

                              Set fdg = Application.Fil eDialog(msoFile DialogFilePicke r)

                              With fdg
                              .AllowMultiSele ct = False
                              .InitialView = msoFileDialogVi ewDetails
                              If .Show = -1 Then
                              For Each vrtSelectedItem In .SelectedItems 'onby be 1
                              strImagePath = vrtSelectedItem
                              strSelectedFile = vrtSelectedItem & "#" & vrtSelectedItem
                              Next vrtSelectedItem
                              Me![txtSelectedFile] = strSelectedFile
                              Select Case Right$(strImage Path, 4)
                              Case ".wmf", ".emf", ".dib", ".bmp", ".ico", ".gif", ".jpg"
                              Me![imgSelectedFile].Picture = strImagePath
                              Case Else
                              Me![imgSelectedFile].Picture = ""
                              End Select
                              Else 'The user pressed Cancel.
                              End If
                              End With

                              Set fdg = Nothing[/CODE]

                              Comment

                              Working...