Results 1 to 7 of 7
  1. #1
    mb4673 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    14

    FileDialog to select a file or a folder

    Hi guys,


    I have this code in one of my forms and it works fine but in a new form I need the option to select a file or a folder, on 1 button.


    My code only allows me to select files.


    Code:
    Private Sub Befehl171_Click()
    On Error Resume Next
    Dim dialog As FileDialog
    Set dialog = Application.FileDialog(msoFileDialogFilePicker)


    With dialog


    .AllowMultiSelect = False
    .Show
    Me.SigePfad = .SelectedItems.Item(1)
    End With
    If Me.SigePfad <> "" Then
    Me.system1 = "1"
    Else
    Me.system1 = ""
    End If
    End Sub


    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    instead of the form, paste this code into a module so ANY form can use it:

    usage:
    vFile = UserPick1File("c:\folder")


    Code:
    Public Function UserPick1File(pvPath)
    Dim strTable As String
    Dim strFilePath As String
    Dim sDialog As String, sDecr  As String, sExt As String
    
    
    If IsMissing(pvPath) Then pvPath = "c:\"
    
    
    With Application.FileDialog(msoFileDialogFilePicker)   'MUST ADD REFERENCE : Microsoft Office 11.0 Object Library
        .AllowMultiSelect = False
        .Title = "Locate a file to Import"
        .ButtonName = "Import"
        .Filters.Clear
        .Filters.Add sDecr, sExt
        .InitialFileName = pvPath
        .InitialView = msoFileDialogViewList    'msoFileDialogViewThumbnail
    
    
            If .show = 0 Then
               'There is a problem
               Exit Function
            End If
    
    
        'Save the first file selected
        UserPick1File = Trim(.SelectedItems(1))
    End With
    End Function

  3. #3
    mb4673 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    14
    Thanks for your code. It's a better version from my code, but i can't select a folder to save it, again I can only select files.

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    select the folder, then type in anything

  6. #6
    mb4673 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    14
    Thanks, but I still have the same problem. I put my test database in the attachment. There I have made a additionally form, where I can select a file or a folder import. But I hope its possible to combine these 2 buttons in 1.
    Attached Files Attached Files

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    I don't think it is possible with the FileDialog. I looked at Shell API code and seems to be the same issue. Best I can suggest is a listbox with two items or an option group with two radio buttons. And then conditional code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Use FileDialog to get file with txt extension
    By newbieX in forum Programming
    Replies: 4
    Last Post: 01-11-2016, 07:28 PM
  2. Replies: 1
    Last Post: 05-15-2015, 10:58 AM
  3. Replies: 43
    Last Post: 03-27-2014, 01:51 AM
  4. FileDialog pass starting Folder as a variable
    By bbrazeau in forum Programming
    Replies: 3
    Last Post: 09-13-2013, 07:23 AM
  5. Replies: 21
    Last Post: 08-20-2012, 11:59 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums