Results 1 to 5 of 5
  1. #1
    nono5551212 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2014
    Posts
    11

    FileCopy - I can Browse and select a file... How can I tell it where to save

    Hello,

    I am creating a button... when clicked it will pull up the Windows File Browser.... and let the user select a file.

    This part I can do. My problem is that I need it to save to a directory I set (It will be the same directory every time)

    How can i get it to save with the original file name to this directory \\server\share

    Say a user... Clicks the button.... points to a file c:\test.txt.. when he clicks ok.... how can I get it to save to \\server\share\test.txt... (The file name will be different every time... Path will be the same)

    Code:
    Private Sub btUploadDoc_Click()
        'First, let the user select the file
        Dim sourcePath As String
        Dim fd As Office.FileDialog
        Set fd = Application.FileDialog(MsoFileDialogType.msoFileDialogFilePicker)
        With fd
            .Title = "Please select file to upload"
            ' Show the dialog and retrieve the final path selected by the user
            .Filters.Clear
            .Filters.Add "All Files", "*.*"
            .AllowMultiSelect = False
            If .Show = True Then
                sourcePath = .SelectedItems(1)
            Else
                Exit Sub
            End If
        End With
        Set fd = Nothing
        
        'Now, do the upload and save the details in the Document table
        FileCopy sourcePath, DestPath
    End Sub

    I need to make this line

    Code:
     FileCopy sourcePath, DestPath
    Take the source file... keeping source name... prefix it with \\server\share...

    so basically when users upload files it will look like
    \\server\share\Test.pdf
    \\server\share\Notes.docx
    Last edited by nono5551212; 01-23-2016 at 12:21 PM.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    You have to start with a full server path because it won't work using drive letters.

    then Capture the path
    I= instrRev(sourcepath,"\")
    sDir = left(sourcepath,I)

  3. #3
    nono5551212 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2014
    Posts
    11
    I don't follow. I must admit I do not know VB at all. Where would your code fit into my code?

    In my mind, and my total lack of VB knowledge... I was hoping for it to look like something I could understand. Like my Example below.


    BELOW IS NOT REAL CODE
    Code:
    Dim sourcePath as String
    Dim destPath as String
    
    
    destPath = "\\server\share"
    
    
    FileCopy sourcePath, destPath + sourceFilename

  4. #4
    nono5551212 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2014
    Posts
    11
    I got this help from a different site... It works...

    I was hoping someone could show me how to add a message box that would say "File Already Exists" if the file already existed..
    and not copy anything if the file already existed

    Code:
    Private Sub Command0_Click()
        Const msoFileDialogFilePicker As Long = 3
        Const DestinationFolder As String = "\\kratos\share\new\"
        Dim fd As Object 'Office.FileDialog
        Dim DestinationPath As String
        Dim sourcePath As String
    
        Set fd = Application.FileDialog(msoFileDialogFilePicker)
        With fd
            .Title = "Please select file to upload"
            .Filters.Clear
            .Filters.Add "All Files", "*.*"
            .AllowMultiSelect = False
            If .Show = True Then
                sourcePath = .SelectedItems(1)
            End If
        End With
        Set fd = Nothing
        If Len(sourcePath) > 0 Then
            DestinationPath = DestinationFolder & Dir(sourcePath)
            Debug.Print DestinationPath '<- inspect this in Immediate window; Ctrl+g will take you there
            FileCopy sourcePath, DestinationPath
        End If
    End Sub

  5. #5
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    use the dir function before the filecopy to check if the file already exists

    see this link on the dir function

    https://msdn.microsoft.com/en-us/lib.../gg278779.aspx

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

Similar Threads

  1. Select File from Computer and Save to Shared Drive
    By sgrimmer in forum Import/Export Data
    Replies: 4
    Last Post: 11-02-2015, 03:43 PM
  2. Faster way to copy a file than FileCopy()
    By kdbailey in forum Access
    Replies: 10
    Last Post: 10-29-2015, 07:20 AM
  3. Browse buttons that save file path into field
    By Zandia in forum Import/Export Data
    Replies: 1
    Last Post: 06-04-2014, 02:55 PM
  4. Replies: 1
    Last Post: 03-18-2014, 05:16 PM
  5. Replies: 22
    Last Post: 02-22-2014, 02:51 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