Results 1 to 12 of 12
  1. #1
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    Saving a file from a server

    I'm trying to download a file from my server then let the user pick where to save it. I have already been able to have the user pick a file and upload it to where I want it to go. I thought it would just be the opposite. I'm having a hard time This is as far as I have gotten. But even this doesn't work the way I want it to. It is incomplete. I want it to just find the file and have the filedialog be there so the user can choose where he wants to save the file. I'm not sure if I'm even close.

    Dim fDialog As filedialog

    Set fDialog = Application.filedialog(msoFileDialogFilePicker)

    With fDialog
    .AllowMultiSelect = False
    .Filters.Clear
    .Filters.Add "Word File", "*.docx;*.doc"
    .FilterIndex = 1


    .InitialFileName = "\\ServerLocation\ServerFolder\Document.docx"
    If .Show Then
    'I haven't made it this far yet
    End If
    End With

  2. #2
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Or if anyone has a link to instructions on how to this

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    So now you want to allow user to select a folder.

    Save the selected file to a variable.
    Code:
    If Not .Show Then
             MsgBox "You clicked Cancel in the file dialog box."
    Else
    strFile = .SelectedItems(1)
    Dim sFolder As String
    Dim fd As FileDialog
    Dim booResult As Boolean
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    fd.AllowMultiSelect = False
    fd.title = "Select database folder"
    fd.InitialFileName = "file:\\"
    While booResult = False
        If fd.Show = True Then
            'folder path was selected
            booResult = True
            sFolder = fd.SelectedItems(1)
            Debug.Print sFolder 'here is where you could take the selected folder path and use it to save file using CopyFile or FileCopy
        End If
    Wend
    End If
    I thought FileCopy is supposed to save a file to destination folder without specifying name to save as, using original file name. However, does not seem to be true. So will have to extract file name from the source file path and concatenate it to the selected folder path.
    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.

  4. #4
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I messed up. Since I already know where the file is, I don't need to have the user select it. I had to start over again. So, I had to get the full path down like this:
    Dim PathFolder As String
    PathFolder = DLookup("FormsPath", "tblSystemDefaults") & "" & txtDocName

    How would I use the file dialog to select where the user wants to save the file? Or is there a better way?

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I already show file dialog code for selecting destination folder.
    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.

  6. #6
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I really thought I was understanding. I'm not so sure now. This is what I did. It brings up the file in the file dialog, but when you choose a destination, it chooses it in the name. Example is when I click on Desktop, the name of the file changed to Desktop.
    Dim PathFolder As String
    PathFolder = DLookup("FormsPath", "tblSystemDefaults") & ""

    Dim sFolder As String
    Dim fd As FileDialog
    Dim booResult As Boolean
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    fd.AllowMultiSelect = False
    fd.Title = "Select folder"
    fd.InitialFileName = PathFolder & Me.txtDocName
    While booResult = False
    If fd.Show = True Then
    'folder path was selected
    booResult = True
    sFolder = fd.SelectedItems(1)
    Debug.Print sFolder
    FileCopy PathFolder & Me.txtDocName, sFolder
    End If
    Wend

  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,929
    Does tblSystemDefaults have only one record? Does FormsPath value have ending \ character? If not, include it in the concatenation.

    FileCopy PathFolder & "\" & Me.txtDocName, sFolder & "\" & Me.txtDocName



    Please post lengthy code between CODE tags to retain indentation and readability. If you had a \ character between those quote marks, the forum dropped it because it saw it as part of a URL string. Go to Advanced editor and uncheck "Automatically parse links in text" every time you edit post so it won't drop \. Otherwise use CODE tags.

    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.

  8. #8
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Yes, tblSystemDefaults has only one record. I found it easier that way. I did include it in the concatenation in PathFolder (PathFolder = DLookup("FormsPath", "tblSystemDefaults") & ""). It didn't come out when I did copy/paste.

  9. #9
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    How do I use code tags?

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    On the post menu bar, click the # button. Paste your code between the tags. Or type the tags.
    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.

  11. #11
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Here's the code:

    Code:
        Dim PathFolder As String
        PathFolder = DLookup("FormsPath", "tblSystemDefaults") & "\"
        
        Dim sFolder As String
        Dim fd As FileDialog
        Dim booResult As Boolean
        Set fd = Application.FileDialog(msoFileDialogFolderPicker)
        fd.AllowMultiSelect = False
        fd.Title = "Select folder"
        fd.InitialFileName = PathFolder & Me.txtDocName
        While booResult = False
            If fd.Show = True Then
                'folder path was selected
                booResult = True
                sFolder = fd.SelectedItems(1)
            Debug.Print sFolder
            FileCopy PathFolder & Me.txtDocName, sFolder & "\" & Me.txtDocName
            End If
        Wend

  12. #12
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    It is working perfectly. Thanks.

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

Similar Threads

  1. Replies: 16
    Last Post: 11-08-2022, 10:46 AM
  2. Replies: 2
    Last Post: 10-06-2021, 10:11 PM
  3. Replies: 2
    Last Post: 04-01-2016, 10:38 AM
  4. Replies: 2
    Last Post: 02-12-2015, 10:59 AM
  5. Replies: 21
    Last Post: 01-24-2012, 06:21 PM

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