Results 1 to 6 of 6
  1. #1
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78

    Move files


    Hello,

    I have the following code which will move a folder and a set of files to another folder. How can I move only the files to the Destination folder without moving the sPrefix folder?

    Code:
    Dim sAttachLocation As String
            sAttachLocation = sTempProjectFiles & Me.txtProjectNumber & sPrefix
            Debug.Print sAttachLocation
    
    
            If Dir(sAttachLocation, vbDirectory) = "" Then
            'do nothing
            Else
    Dim sDestination As String
    If IsNull(Me.EstimateFolderLocation) Then CreateEstimateRequestForm Me, Cancel, bProject, bWorkorder, bCompleteDt End If sDestination = Me.EstimateFolderLocation & "03) Scope_Engineering_Costs\" Debug.Print sDestination Dim fso As Object Set fso = CreateObject("Scripting.FileSystemObject") fso.CopyFolder sAttachLocation, sDestination
    I tried using CopyFiles but I got Run-time error '438': Object doesn't support this property or method.
    Code:
    fso.CopyFiles sAttachLocation, sDestination

    Image shows how it saves it, I'd like to just move the files


    Click image for larger version. 

Name:	Screenshot 2022-09-23 152454.png 
Views:	24 
Size:	21.1 KB 
ID:	48796

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    to move:
    Name sSrcFile As sTargFile

  3. #3
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Usually to move all files in a folder you'll need a loop.

    Here is Google search that returns many, many answers:

    https://www.google.com/search?q=vba+...hrome&ie=UTF-8

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    Your in the right ballpark with FSO. If your not overly familiar with all the filesystemobject methods, I'd suggest using early binding so at least you get intellisense.
    Makes things much easier and you can easily change it to late binding when everything works.

    As Vlad stated you'll need a loop.
    Get a pointer to a folder with FSO.Getfolder(Path To Folder)
    Then loop through the folder's file collection -ie. For each fil in fol.files ...
    Use the MoveFile method for each file in the loop.

    Here's a link which lists most of the available methods with examples. It's excel but no different in access.

    https://analystcave.com/vba-filesyst...-fso-in-excel/
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78
    Thanks for the resources, they were really helpful. After some trial and error I was able to successfully move the files with the following:

    Code:
            Dim fso As Object
            Dim FileExt As String
            
            Set fso = CreateObject("Scripting.FileSystemObject")
            FileExt = "\*.*"
            fso.CopyFile Source:=sAttachLocation & FileExt, Destination:=sDestination

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    Another method looks like this
    Code:
    Sub MoveMyFiles(strSource As String, strDestination As String)
    
    
        Dim fol As Folder, fil As File
    
    
        Dim fso As New FileSystemObject
    
    
        Set fol = fso.GetFolder(strSource)
    
    
        For Each fil In fol.Files
    
    
            fso.MoveFile fil.Path, fso.BuildPath(strDestination, fil.Name)
    
    
        Next
    
    
    End Sub
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Replies: 10
    Last Post: 09-09-2015, 03:25 AM
  2. Batch Script to Move Files
    By littleheart_Sony in forum Programming
    Replies: 5
    Last Post: 06-20-2015, 12:06 AM
  3. Replies: 3
    Last Post: 12-11-2014, 11:26 AM
  4. Replies: 1
    Last Post: 11-07-2013, 11:15 AM
  5. Replies: 1
    Last Post: 02-21-2011, 09:55 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