How can I create a prompt that allows a user to select a folder in a dialog?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Mullin
    New Member
    • Aug 2010
    • 48

    How can I create a prompt that allows a user to select a folder in a dialog?

    Hello all,

    I have another tedious request that I cannot figure out on my own but hopefully you guys can answer.

    On one of the forms the user interacts with there is a field (linked to a table) that is formatted as a hyperlink that allows the user to paste in the location of that specific record's folder on the shared drive. (to save the hassle of clicking through the various folders on the shared drive to find a specific one every time it needs to be accessed)

    If possible I would like to have a button that launches the basic Windows "Select a Folder" dialog box. After the user selects a folder using the dialog box, the location appears in the shard folder field and stored there for future use.

    I'm not sure if this is possible but I would imagine it is.

    Thanks for he help, it is greatly appreciated!
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    1. First, set a Reference to the Microsoft Office XX.X Object Library.
    2. Copy-N-Paste the following Code to wherever appropriate:
      Code:
      Dim strButtonCaption As String
      Dim strDialogTitle As String
      
      'Define your own Captions if necessary
      strButtonCaption = "Select a Folder"
      strDialogTitle = "Folder Selection Dialog"
      
      With Application.FileDialog(msoFileDialogFolderPicker)
        .ButtonName = strButtonCaption
        .InitialView = msoFileDialogViewDetails     'Detailed View
        .Title = strDialogTitle
           If .Show Then
             Me![txtLocation] = .SelectedItems(1)         'Write Folder Path to Field
           End If
      End With

    Comment

    • Tim Mullin
      New Member
      • Aug 2010
      • 48

      #3
      Thank you for the reply - however I do not follow your first instruction. Sorry if it should be something straightforward , I'm an amateur at Access...

      Also if the two object involved are a text field and a button, where would I post the code?

      Thanks again, I really appreciate it!

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        1. In any Code View Window, click on Tools, References. Scroll down to the Microsoft Office XX.X Object Library, select the Check Box, then OK.
        2. This Code would typically go in the Click() Event of a Command Button.

        Comment

        • Tim Mullin
          New Member
          • Aug 2010
          • 48

          #5
          Ok, I got the first part complete. To apply the code correctly I need to make a module with that code and set the onclick to RunCode for that module, correct? I have attached a picture to show how the module is set up...

          Comment

          • Tim Mullin
            New Member
            • Aug 2010
            • 48

            #6
            I tried a few more things and think i got to where I want to paste the code...however when i click the button it launches the vba editor and says there is a code compile error... any suggestions?

            Comment

            • Tim Mullin
              New Member
              • Aug 2010
              • 48

              #7
              GOT IT! I went back and deleted the first module I created and then I was able to open the dialog box. From there I had to change the location of the field from the full [Forms]![Clients]![Shared Folder] to simply [Shared Folder].

              Works like a charm! Thank you so much!

              Comment

              • Tim Mullin
                New Member
                • Aug 2010
                • 48

                #8
                It looks like I spoke to soon...

                For some reason when the folder path is displayed in the field (the field is formatted as a hyperlink) when you click on it nothing happens. It looks as though its a hyperlink, but an explorer window open to that folder does not appear as it does if you copy and paste the folder path into the field... Any suggestions??

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  You are quite welcome, way to hang in there!

                  Comment

                  • Tim Mullin
                    New Member
                    • Aug 2010
                    • 48

                    #10
                    Any suggestions on making the displayed text an active hyperlink? I can't seem to figure it out...

                    Comment

                    • Steven Kogan
                      Recognized Expert New Member
                      • Jul 2010
                      • 107

                      #11
                      Set the Is Hyperlink property of the field to Yes. That is in the Format tab of properties. This will format the field as a hyperlink and display the hand symbol when you hover over it.

                      Then in the click event put:
                      Code:
                      FollowHyperlink Me.YourFieldName
                      Replacing 'YourFieldName' with the control or fieldname.

                      Comment

                      • Tim Mullin
                        New Member
                        • Aug 2010
                        • 48

                        #12
                        Awesome! Thank you so much, it works perfectly now. I appreciate all the help!

                        Comment

                        Working...