Folder Dialog box with Make New Folder option

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CD Tom
    Contributor
    • Feb 2009
    • 495

    Folder Dialog box with Make New Folder option

    In my application I have an option to backup the data it creates a .txt file for each table. I'm using some old code that is quite lengthy and was created for access 2002. I would like to see if there is some new code. I want the user to be able to select from a standard windows dialog box, select a given folder but I would like to have the user be able to also be able to make a new folder. When the folder is either selected or a new folder is created the data from the tables will be entered into the selected folder. I'm using the standard DoCmd.TransferT ext to export the data.
    Like I mentioned the code I'm using now works fine but it is very large and takes some time to work.
    I've been looking at some of the code and lots of the Folder Dialog is quite small and brings up the standard dialog box but there is no option to make a folder.
    Thanks for any help.
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi

    I tend to use this when I need to select a folder/file
    Code:
    Option Compare Database
    Option Explicit
    
    Sub SelectFolder()
        Dim fd As FileDialog
        Dim strFolder As String
         
        Set fd = Application.FileDialog(msoFileDialogFolderPicker)
        With fd
            .AllowMultiSelect = False
            If .Show = -1 Then
                strFolder = .SelectedItems(1)
                MsgBox strFolder
            End If
        End With
    End Sub
    I am currently on Access 2007, the above code opens a standard dialogue box that includes an add 'New Folder' button.

    This code requires a reference to the Microsoft Office Object Library.

    This will obviously need amending to suit your purpose.

    HTH

    MTB

    Comment

    • CD Tom
      Contributor
      • Feb 2009
      • 495

      #3
      I like the looks of this dialog but it seems to be wanting me to type in a file name, I'm adding about 20 files with different name and the extension .txt After I select the folder I just want the files to be put in the selected folder.

      Comment

      • MikeTheBike
        Recognized Expert Contributor
        • Jun 2007
        • 640

        #4
        The routine I posted is purely to illustrate how to pick/create a folder and return its path to the program/code.
        You will need to write some code to loop through the list of items you want to save using the folder path and the DoCmd.TransferT ext you have suggested.

        Cannot help too much with that as I never use DoCmd.Transer.. .. command to save info to disc/network, but I am sure there other more capable then I that can.


        MTB

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          The following Demo using the Windows Browse For Folder Dialog will allow you to either Select an existing Folder or create a New Folder. The Fully Qualified PATH to this Folder will be contained in varRet. After retrieving this Folder it will be a simple matter to Transfer Data to it.
          Attached Files

          Comment

          • CD Tom
            Contributor
            • Feb 2009
            • 495

            #6
            My error in the set fd I picked the file picker instead of the folder picker. That works great thanks, this is much less code.

            Comment

            • CD Tom
              Contributor
              • Feb 2009
              • 495

              #7
              Just a quick question is there a way to tell the dialog box to highlight a start folder? Say I want the dialog box to start with a folder called c:\backups
              Thanks

              Comment

              • MikeTheBike
                Recognized Expert Contributor
                • Jun 2007
                • 640

                #8
                Code:
                Sub SelectFolder()
                    Dim fd As FileDialog
                    Dim strFolder As String
                     
                    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
                    With fd
                        .InitialFileName = "c:\backups"
                        .AllowMultiSelect = False
                        If .Show = -1 Then
                            strFolder = .SelectedItems(1)
                            MsgBox strFolder
                        End If
                    End With
                End Sub
                Just use the .InitialFileNam e property as above.
                There are other properties/methods you can use. Just use the IntelliSense on the dialogue object.

                HTH


                MTB

                Comment

                • CD Tom
                  Contributor
                  • Feb 2009
                  • 495

                  #9
                  That's exactly what I was looking for. I'll look into the other options.
                  Thanks again for your help.

                  Comment

                  Working...